//USBtinyISP(ATTinyCore) upload using programmer //Atinny841(Optiboot) const int RED = 4; //LED row 1 const int GREEN = 3; //LED row 2 const int BLUE = 2; //LED row 3 static uint16_t hue = 0; // 0-359 unsigned long previousMillis = 0; int shift = 0; void setup() { previousMillis = millis() + 5000; pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT); pinMode(BLUE, OUTPUT); } void loop() { randomSeed(analogRead(0)); if (shift==1) { for (int hue=0; hue<360; hue++) { setLedColorHSV(hue,random(1, 5),random(1, 5)); delay(random(1, 25)); } } if (shift==0) { for (int hue=360; hue>0; hue--) { setLedColorHSV(hue,random(1, 5),random(1, 5)); delay(random(1, 25)); } } if (((signed long)(millis() - previousMillis)) > 0) { previousMillis = millis() + 3000; long dice = random(1000); if (dice > 900) { glowgreen(); shift=1; RGB_color(0,100,0); } else if (dice<100) { glowblue(); shift=0; RGB_color(100,0,0); } } } void RGB_color(int red_light_value, int green_light_value, int blue_light_value) { analogWrite(RED, red_light_value); analogWrite(GREEN, green_light_value); analogWrite(BLUE, blue_light_value); } void setLedColorHSV(int h, double s, double v) { //this is the algorithm to convert from RGB to HSV double r=0; double g=0; double b=0; double hf=h/60.0; int i=(int)floor(h/60.0); double f = h/60.0 - i; double pv = v * (1 - s); double qv = v * (1 - s*f); double tv = v * (1 - s * (1 - f)); switch (i) { case 0: //rojo dominante r = v; g = tv; b = pv; break; case 1: //verde r = qv; g = v; b = pv; break; case 2: r = pv; g = v; b = tv; break; case 3: //azul r = pv; g = qv; b = v; break; case 4: r = tv; g = pv; b = v; break; case 5: //rojo r = v; g = pv; b = qv; break; } //set each component to a integer value between 0 and 255 int red=constrain((int)255*r,0,255); int green=constrain((int)255*g,0,255); int blue=constrain((int)255*b,0,255); RGB_color(red,green,blue); } void glowgreen() { for(uint16_t t=0; t<255; t++) { RGB_color(0,t,0); delay(random(1, 25)); } for(uint16_t t=255; t>0; t--) { RGB_color(0,t,0); delay(random(1, 25)); } } void glowblue() { for(uint16_t t=0; t<255; t++) { RGB_color(0,0,t); delay(random(1, 25)); } for(uint16_t t=255; t>0; t--) { RGB_color(0,0,t); delay(random(1, 25)); } }