#include <FastLED.h>
#include "FastLED_RGBW.h" // hacked library for SK6812 RGBW strips
#define LED_PIN 3
#define LED_PIN2 5
#define LED_PIN3 6
#define LED_PIN4 9
#define LED_PIN5 10
#define LED_PIN6 11
#define NUM_LEDS 12
#define NUM_LEDS2 14
#define NUM_LEDS3 12
#define NUM_LEDS4 12
#define NUM_LEDS5 28
#define NUM_LEDS6 48
#define BRIGHTNESS 255
int debounceDelay =250;
int lastDebounceTime =0;
CRGBW leds[NUM_LEDS];
CRGB *ledsRGB = (CRGB *) &leds[0];
CRGBW leds2[NUM_LEDS2];
CRGB *ledsRGB2 = (CRGB *) &leds2[0];
CRGBW leds3[NUM_LEDS3];
CRGB *ledsRGB3 = (CRGB *) &leds3[0];
CRGBW leds4[NUM_LEDS4];
CRGB *ledsRGB4 = (CRGB *) &leds4[0];
CRGBW leds5[NUM_LEDS5];
CRGB *ledsRGB5 = (CRGB *) &leds5[0];
CRGBW leds6[NUM_LEDS6];
CRGB *ledsRGB6 = (CRGB *) &leds6[0];
#define btn 12
// button for brightness change, connect with pulldown resistor
byte brightness2 = 255;
int x = 1;
int y = 0;
int z = 0;
boolean oldState = HIGH;
unsigned long first_pressed_millis = 0;
volatile int mode = 1; // Currently-active animation mode
volatile int functionflag;
const int functionButton = 0;
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, RGB>(ledsRGB, getRGBWsize(NUM_LEDS));
FastLED.addLeds<WS2812B, LED_PIN2, RGB>(ledsRGB2, getRGBWsize(NUM_LEDS2));
FastLED.addLeds<WS2812B, LED_PIN3, RGB>(ledsRGB3, getRGBWsize(NUM_LEDS3));
FastLED.addLeds<WS2812B, LED_PIN4, RGB>(ledsRGB4, getRGBWsize(NUM_LEDS4));
FastLED.addLeds<WS2812B, LED_PIN5, RGB>(ledsRGB5, getRGBWsize(NUM_LEDS5));
FastLED.addLeds<WS2812B, LED_PIN6, RGB>(ledsRGB6, getRGBWsize(NUM_LEDS6));
Serial.begin(9600);
pinMode(functionButton, INPUT);
attachInterrupt(digitalPinToInterrupt(2), Myisr, RISING); // trigger when button pressed, but not when released.
Serial.println("start");
}
void loop() {
Serial.println("it is started loop");
boolean newState = digitalRead(functionButton);
noInterrupts();
int localMode = mode;
interrupts();
Serial.println("local mode");
Serial.println(localMode);
//Serial.printlnC(newState);
//if(newState == HIGH) {
// Serial.println(newState);
start:
Serial.println("mode=");
Serial.println(mode);
switch (mode) { // Start the new animation...
case 0:
while (digitalRead(12)==0) { // code to be executed repeatedly
Serial.println("case 0");
fillWhite(); //white only
FastLED.delay(110);
fade_down();
FastLED.clear();
FastLED.setBrightness(BRIGHTNESS);
FastLED.delay(1500);
goto start;
}
break;
case 1: //Red only
while (digitalRead(12)==0) {
Serial.println("case 1");
fillred();
FastLED.delay(110);
FastLED.delay(220);
fade_down2();
FastLED.clear();
FastLED.delay(1500);
goto start;
}
break;
case 2:
while (digitalRead(12)==0) {
Serial.println("case 2");
// white and red
fillWhite();
FastLED.delay(110);
fade_down();
FastLED.clear();
FastLED.setBrightness(BRIGHTNESS);
FastLED.delay(1500);
FastLED.clear();
FastLED.delay(1500);
fillred();
FastLED.delay(110);
FastLED.delay(220);
fade_down2();
FastLED.clear();
FastLED.delay(1500);
goto start;
}
break;
case 3:
while (digitalRead(12)==0) {
Serial.println("case 3");
// this is just an test for changing function
leds[0] = CRGB::Red;
leds[1] = CRGB::Red;
leds[2] = CRGB::Red;
leds[3] = CRGB::Red;
leds[4] = CRGB::Red;
leds[5] = CRGB::Red;
FastLED.show();
goto start;
}
break;
}
//}
//oldState = newState;
if(digitalRead(btn) == HIGH){
ChangeBrightness();
}
}
void Myisr() {
Serial.println("interrupt called");
if (millis() - lastDebounceTime > debounceDelay) {
mode++;
if (mode > 4) {
mode = 0;
}
lastDebounceTime = millis();
}
Serial.println("MD=");
Serial.println(mode);
}
void ChangeBrightness(){
Serial.println("brightness changed");
if (brightness2 == 255) {
brightness2 = 150;
Serial.println(brightness2);
} else if (brightness2 == 150) {
brightness2 = 25;
Serial.println(brightness2);
} else if (brightness2 == 25) {
brightness2 = 255;
Serial.println(brightness2);
}
FastLED.setBrightness(brightness2);
FastLED.show();
}
void fade_down() {
byte brightness;
while ((brightness = FastLED.getBrightness()) > 0) {
FastLED.setBrightness(--brightness);
FastLED.show(); // This sends the updated pixel brightness to the hardware.
delay(10);
}
}
void fade_down2() {
for (int y = 255; y >= 0; y--) {
FastLED.setBrightness(y);
leds[y] = CRGBW(255, 0, 0, 0);
FastLED.show();
FastLED.delay(10);
}
}
void fillWhite() {
for (int i = 11; i >= 0; i--) {
leds[i] = CRGBW(0, 0, 0, 255);
FastLED.show();
delay(50);
}
FastLED.delay(110);
for (int i = 13; i >= 0; i--) {
leds2[i] = CRGBW(0, 0, 0, 255);
FastLED.show();
delay(50);
}
FastLED.delay(110);
for (int i = 11; i >= 0; i--) {
leds3[i] = CRGBW(0, 0, 0, 255);
FastLED.show();
delay(50);
}
FastLED.delay(110);
for (int i = 11; i >= 0; i--) {
leds4[i] = CRGBW(0, 0, 0, 255);
FastLED.show();
delay(50);
}
FastLED.delay(110);
for (int i = 27; i >= 0; i--) {
leds5[i] = CRGBW(0, 0, 0, 255);
FastLED.show();
delay(15);
}
FastLED.delay(110);
y = 23;
for (int i = 24; i > 0; i--) {
leds6[i] = CRGBW(0, 0, 80, 200);
leds6[y] = CRGBW(0, 0, 80, 200);
y = y + 1;
FastLED.show();
delay(15);
}
}
void fillred() {
for (int i = 11; i >= 0; i--) {
leds[i] = CRGBW(255, 0, 0, 0);
FastLED.show();
delay(50);
}
FastLED.delay(110);
for (int i = 13; i >= 0; i--) {
leds2[i] = CRGBW(255, 0, 0, 0);
FastLED.show();
delay(50);
}
FastLED.delay(110);
for (int i = 11; i >= 0; i--) {
leds3[i] = CRGBW(255, 0, 0, 0);
FastLED.show();
delay(50);
}
FastLED.delay(110);
for (int i = 11; i >= 0; i--) {
leds4[i] = CRGBW(255, 0, 0, 0);
FastLED.show();
delay(50);
}
FastLED.delay(110);
for (int i = 27; i >= 0; i--) {
leds5[i] = CRGBW(255, 0, 0, 0);
FastLED.show();
delay(15);
}
FastLED.delay(110);
y = 23;
for (int i = 24; i > 0; i--) {
leds6[i] = CRGBW(255, 0, 0, 0);
leds6[y] = CRGBW(255, 0, 0, 0);
y = y + 1;
FastLED.show();
delay(15);
}
}