#include /* Blue Robotics Lumen LED Embedded Software ------------------------------------------------ Title: Lumen LED Light Embedded Microcontroller Software, modified by Seatools Pty Ltd Description: This file is used on the ATtiny45 microcontroller on the Lumen LED Light and controls the dimming of the light, using serial commands. Additionally, a thermistor is used to sense temperature and automatically dim the light to level 1 if it is overheating. ------------------------------- The MIT License (MIT) Copyright (c) 2016 Blue Robotics Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------*/ // HARDWARE PIN DEFINITIONS #define LED_PIN 1 // pin 6 #define TEMP_PIN A1 // pin 7 #define rxPin 0 // D0, Pin 5 #define txPin -1 // undefined pin, ignore // set up serial port SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin, true); char c; int ilevel = 0; bool first_dim = true; void setup() { pinMode(LED_PIN,OUTPUT); // define pin mode for rx: pinMode(rxPin, INPUT); // set the data rate for the SoftwareSerial port mySerial.begin(9600); // Setup up PWM on output pin // The default analogWrite frequency can mess with cameras TCCR0B = _BV(CS01); // Set prescalar to 8 for 8M/8/256 = 3906 Hz } void loop() { // Read serial input if available, use serial code to set dimming level while (mySerial.available()){ c = mySerial.read(); // Output PWM to LED driver based on character read from serial input if (c == '0') { digitalWrite(LED_PIN, LOW); } else if (c == '1') { analogWrite(LED_PIN, 21); } else if (c == '2') { analogWrite(LED_PIN, 70); } else if (c == '3') { analogWrite(LED_PIN, 120); } else if (c == '4') { analogWrite(LED_PIN, 170); } else if (c == '5') { analogWrite(LED_PIN, 230); } } // temperature dimming - reduce to level 1 and flash a couple of times if (analogRead(TEMP_PIN)<= 265 && c != '0'){ if (first_dim) { analogWrite(LED_PIN, 21); delay(500); analogWrite(LED_PIN, LOW); delay(500); analogWrite(LED_PIN, 21); delay(500); analogWrite(LED_PIN, LOW); delay(500); analogWrite(LED_PIN, 21); first_dim = false; } } if (analogRead(TEMP_PIN)> 355 && first_dim == false){ if (c == '0') { digitalWrite(LED_PIN, LOW); } else if (c == '1') { analogWrite(LED_PIN, 21); } else if (c == '2') { analogWrite(LED_PIN, 70); } else if (c == '3') { analogWrite(LED_PIN, 120); } else if (c == '4') { analogWrite(LED_PIN, 170); } else if (c == '5') { analogWrite(LED_PIN, 230); } first_dim = true; } delay(50); }