//ATtiny85 MASON JAR Mood Light //Date : 28/12/2014 const int redPin = 2; const int grnPin = 1; const int bluPin = 0; const int LDRpin = 3; int lightThresh = 250; // Light threshold. 0 - 1023. Lower number = activation at lower light level. void setup() { pinMode(redPin, OUTPUT); pinMode(grnPin, OUTPUT); pinMode(bluPin, OUTPUT); pinMode(LDRpin, INPUT); } void loop() { if (analogRead(LDRpin) < lightThresh) { redtoyellow(); yellowtogreen(); greentocyan(); cyantoblue(); bluetomagenta(); magentatored(); } else if (analogRead(LDRpin) >= lightThresh) { digitalWrite(redPin, HIGH); digitalWrite(grnPin, HIGH); digitalWrite(bluPin, HIGH); } } void redtoyellow() { digitalWrite(redPin, LOW); digitalWrite(bluPin, HIGH); // fade up green for(byte i=1; i<100; i++) { byte on = i; byte off = 100-on; for( byte a=0; a<100; a++ ) { digitalWrite(grnPin, LOW); delayMicroseconds(on); digitalWrite(grnPin,HIGH); delayMicroseconds(off); } } } void yellowtogreen() { digitalWrite(grnPin, LOW); digitalWrite(bluPin,HIGH); // fade down red for(byte i=1; i<100; i++) { byte on = 100-i; byte off = i; for( byte a=0; a<100; a++ ) { digitalWrite(redPin, LOW); delayMicroseconds(on); digitalWrite(redPin, HIGH); delayMicroseconds(off); } } } void greentocyan() { digitalWrite(grnPin, LOW); digitalWrite(redPin, HIGH); // fade up blue for(byte i=1; i<100; i++) { byte on = i; byte off = 100-on; for( byte a=0; a<100; a++ ) { digitalWrite(bluPin, LOW); delayMicroseconds(on); digitalWrite(bluPin, HIGH); delayMicroseconds(off); } } } void cyantoblue() { digitalWrite(bluPin, LOW); digitalWrite(redPin, HIGH); // fade down green for(byte i=1; i<100; i++) { byte on = 100-i; byte off = i; for( byte a=0; a<100; a++ ) { digitalWrite(grnPin, LOW); delayMicroseconds(on); digitalWrite(grnPin,HIGH); delayMicroseconds(off); } } } void bluetomagenta() { digitalWrite(bluPin, LOW); digitalWrite(grnPin,HIGH); // fade up red for(byte i=1; i<100; i++) { byte on = i; byte off = 100-on; for( byte a=0; a<100; a++ ) { digitalWrite(redPin, LOW); delayMicroseconds(on); digitalWrite(redPin, HIGH); delayMicroseconds(off); } } } void magentatored() { digitalWrite(redPin,LOW); digitalWrite(grnPin, HIGH); // fade down blue for(byte i=1; i<100; i++) { byte on = 100-i; byte off = i; for( byte a=0; a<100; a++ ) { digitalWrite(bluPin, LOW); delayMicroseconds(on); digitalWrite(bluPin, HIGH); delayMicroseconds(off); } } }