#include <Adafruit_NeoPixel.h>
#define FPS 100
#define BLINK 750
#define PIN 2
#define NUMPIXELS 75
Adafruit_NeoPixel Pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
bool WOKWI = true;
bool DEBUG = true;
uint8_t ListOfLeds[10]; // needs to be global for the Meteor effect
uint8_t ListItems = 0;
String PHASE = "";
bool NEW_EFFECT = true;
int EFFECT_COUNTER = 0;
struct STRUCT_LED{
const char* Name;
const char* Group;
uint16_t Index;
uint32_t Hue_B;
uint32_t Hue;
uint8_t Val_B;
uint8_t Val;
uint8_t Sat_B;
uint8_t Sat;
uint8_t Effect_B;
uint8_t Effect;
uint8_t Inc_B;
uint8_t Inc;
uint8_t X;
uint8_t Y;
int Rep;
unsigned long Timer;
bool Default;
bool Active;
};
STRUCT_LED Led[200] = {
{"ORBIT1","ORBIT", 0,0,0,0,0,0,0,0,0,0,0,5,71},
{"ORBITA1","ORBITAA", 6,0,0,0,0,0,0,0,0,0,0,11,53},
{"ORBITA2","ORBITAA", 5,0,0,0,0,0,0,0,0,0,0,10,55},
{"ORBITB1","ORBITAB", 4,0,0,0,0,0,0,0,0,0,0,9,59},
{"ORBITB2","ORBITAB", 3,0,0,0,0,0,0,0,0,0,0,8,61},
{"ORBITC1","ORBITAC", 2,0,0,0,0,0,0,0,0,0,0,7,64},
{"ORBITC2","ORBITAC", 1,0,0,0,0,0,0,0,0,0,0,4,67},
{"RAMPL","RAMPL", 7,0,0,0,0,0,0,0,0,0,0,20,54},
{"RAMPLA1","RAMPLA", 9,0,0,0,0,0,0,0,0,0,0,21,48},
{"RAMPLA2","RAMPLA", 8,0,0,0,0,0,0,0,0,0,0,21,50},
{"DROP1","DROPS", 13,0,0,0,0,0,0,0,0,0,0,5,38},
{"DROP2","DROPS", 12,0,0,0,0,0,0,0,0,0,0,6,43},
{"DROP3","DROPS", 11,0,0,0,0,0,0,0,0,0,0,7,47},
{"DROP4","DROPS", 10,0,0,0,0,0,0,0,0,0,0,8,51},
{"DROPA1","DROPA", 16,0,0,0,0,0,0,0,0,0,0,11,40},
{"DROPA2","DROPA", 15,0,0,0,0,0,0,0,0,0,0,10,42},
{"GIL","GIL", 14,0,0,0,0,0,0,0,0,0,0,0,0},
{"ESCAPEA1","ESCAPEA",17,0,0,0,0,0,0,0,0,0,0,6,23},
{"ESCAPEA2","ESCAPEA",18,0,0,0,0,0,0,0,0,0,0,5,22},
{"OUTLANEL","LANES", 19,0,0,0,0,0,0,0,0,0,0,7,17},
{"INLANEL","LANES", 20,0,0,0,0,0,0,0,0,0,0,13,20},
{"NA1","NA", 21,0,0,0,0,0,0,0,0,0,0,19,23},
{"NA2","NA", 22,0,0,0,0,0,0,0,0,0,0,21,23},
{"SA1","SA", 23,0,0,0,0,0,0,0,0,0,0,21,15},
{"SA2","SA", 24,0,0,0,0,0,0,0,0,0,0,23,15},
{"MULTI1","MULTI", 25,0,0,0,0,0,0,0,0,0,0,24,6},
{"MULTI2","MULTI", 26,0,0,0,0,0,0,0,0,0,0,27,7},
{"MULTI3","MULTI", 27,0,0,0,0,0,0,0,0,0,0,30,7},
{"MULTI4","MULTI", 28,0,0,0,0,0,0,0,0,0,0,34,7},
{"MULTI5","MULTI", 29,0,0,0,0,0,0,0,0,0,0,38,6},
{"SHOOT1","SHOOT", 30,0,0,0,0,0,0,0,0,0,0,29,1},
{"SHOOT2","SHOOT", 31,0,0,0,0,0,0,0,0,0,0,31,1},
{"SHOOT3","SHOOT", 32,0,0,0,0,0,0,0,0,0,0,31,2},
{"SHOOT4","SHOOT", 33,0,0,0,0,0,0,0,0,0,0,29,2},
{"AU1","AU", 34,0,0,0,0,0,0,0,0,0,0,36,11},
{"AU2","AU", 35,0,0,0,0,0,0,0,0,0,0,38,11},
{"MAD1","MAD", 36,0,0,0,0,0,0,0,0,0,0,31,12},
{"MAD2","MAD", 37,0,0,0,0,0,0,0,0,0,0,30,12},
{"MAD3","MAD", 38,0,0,0,0,0,0,0,0,0,0,30,13},
{"MAD4","MAD", 39,0,0,0,0,0,0,0,0,0,0,31,13},
{"EU1","EU", 40,0,0,0,0,0,0,0,0,0,0,29,20},
{"EU2","EU", 41,0,0,0,0,0,0,0,0,0,0,30,20},
{"AZ1","AZ", 42,0,0,0,0,0,0,0,0,0,0,40,23},
{"AZ2","AZ", 43,0,0,0,0,0,0,0,0,0,0,38,23},
{"INLANER","LANES", 44,0,0,0,0,0,0,0,0,0,0,48,20},
{"OUTLANER","LANES", 45,0,0,0,0,0,0,0,0,0,0,53,17},
{"TUNNELE","TUNNELE", 46,0,0,0,0,0,0,0,0,0,0,5,50},
{"TIREA1","TIREA", 47,0,0,0,0,0,0,0,0,0,0,5,50},
{"TIREA2","TIREA", 48,0,0,0,0,0,0,0,0,0,0,5,50},
{"TIRE1","TIRES", 49,0,0,0,0,0,0,0,0,0,0,5,50},
{"TIRE2","TIRES", 50,0,0,0,0,0,0,0,0,0,0,5,50},
{"TIRE3","TIRES", 51,0,0,0,0,0,0,0,0,0,0,5,50},
{"TIRE4","TIRES", 52,0,0,0,0,0,0,0,0,0,0,5,50},
{"CURVAA1","CURVAA", 53,0,0,0,0,0,0,0,0,0,0,5,50},
{"RAMPRA1","RAMPRA", 54,0,0,0,0,0,0,0,0,0,0,5,50},
{"RAMPRA2","RAMPRA", 55,0,0,0,0,0,0,0,0,0,0,5,50},
{"CURVAA2","CURVAA", 56,0,0,0,0,0,0,0,0,0,0,5,50},
{"CURVA1","CURVA", 57,0,0,0,0,0,0,0,0,0,0,5,50},
{"METEOR1","METEOR", 58,0,0,0,0,0,0,0,0,0,0,5,50},
{"METEOR2","METEOR", 59,0,0,0,0,0,0,0,0,0,0,5,50},
{"METEOR3","METEOR", 60,0,0,0,0,0,0,0,0,0,0,5,50},
{"METEOR4","METEOR", 61,0,0,0,0,0,0,0,0,0,0,5,50},
{"METEOR5","METEOR", 62,0,0,0,0,0,0,0,0,0,0,5,50},
{"METEOR6","METEOR", 63,0,0,0,0,0,0,0,0,0,0,5,50},
{"METEOR7","METEOR", 64,0,0,0,0,0,0,0,0,0,0,5,50},
{"SBA1","SBA", 65,0,0,0,0,0,0,0,0,0,0,5,50},
{"SBA2","SBA", 66,0,0,0,0,0,0,0,0,0,0,5,50},
{"GATEA1","GATEA", 69,0,0,0,0,0,0,0,0,0,0,5,50},
{"GATEA2","GATEA", 70,0,0,0,0,0,0,0,0,0,0,5,50},
{"GATE1","GATES", 67,0,0,0,0,0,0,0,0,0,0,5,50},
{"GATE2","GATES", 68,0,0,0,0,0,0,0,0,0,0,5,50},
{"GATE3","GATES", 71,0,0,0,0,0,0,0,0,0,0,5,50},
{"GATE4","GATES", 72,0,0,0,0,0,0,0,0,0,0,5,50}
};
void setup() {
Serial.begin(9600);
while (!Serial) {
}
COM("Serial established");
Serial.setTimeout(10);
// if (!WOKWI) {
// RPC.begin(); // Alleen op de echte Giga
// RPC.bind("SET_LED", SETTINGS_LED_NEW);
// }
Pixels.begin();
Pixels.show();
}
void loop() {
if (WOKWI) {
if (Serial.available() > 0) {
String TYPE = Serial.readStringUntil(','); // B(ase) or E(ffect)
String MODE = Serial.readStringUntil(',');
String NAME = Serial.readStringUntil(',');
String KLEUR = Serial.readStringUntil(',');
String GETAL = Serial.readStringUntil('\n');
int EFFECT = GETAL.toInt();
uint16_t HUE = KLEUR.toInt();
if (TYPE = "PHASE") {
// COM("Mode called");
if (MODE == "STARTUP") {
// COM("Phase STARTUP called");
SHOW_STARTUP();
} else
if (MODE == "ATTRACT") {
SHOW_ATTRACT();
} else
if (MODE == "PASSIVE") {
SHOW_PASSIVE();
}
} else
{
// COM("PHASE="+ PHASE);
SETTINGS_LED_NEW(TYPE,MODE,NAME,HUE,EFFECT);
}
TYPE = "";
MODE = "";
NAME = "";
KLEUR = "";
GETAL = "";
}
if (PHASE == "ATTRACT") {
// COM("Phase ATTRACT called");
SHOW_ATTRACT();
} else
if (PHASE == "PASSIVE") {
// COM("Phase PASSIVE called");
SHOW_PASSIVE();
}
}
SETTINGS_LED_EVALUATE();
Pixels.show();
}
// OFF=0, ON=1, Fadein=2, Fadeout=3, Pulse=4, EFFECT_Breathe=5, Flash=6, Blink=7, Hit=8, 9=Meteor, 10=Trail
// B,S,GATE1,0
void SETTINGS_LED_NEW(String TYPE, String MODE, String NAME, uint16_t HUE, uint8_t EFFECT) {
uint8_t ListItems = 0;
for (uint8_t C=0 ; C < sizeof(Led) / sizeof(Led[0]) ; C++ ) {
if (MODE=="S" && strcmp(Led[C].Name, NAME.c_str()) == 0) {
ListOfLeds[ListItems] = C;
ListItems++;
} else
if (MODE=="M" && strcmp(Led[C].Group, NAME.c_str()) == 0) {
ListOfLeds[ListItems] = C;
ListItems++;
}
}
// COM("Listitems :" + String(ListItems));
for (uint8_t i=0 ; i<ListItems ; i++) {
if (TYPE=="E") {// write current LED settings to *_B
// COM("Backup the led values for after the effect");
Led[ListOfLeds[i]].Hue_B = Led[ListOfLeds[i]].Hue;
Led[ListOfLeds[i]].Sat_B = Led[ListOfLeds[i]].Sat;
Led[ListOfLeds[i]].Val_B = Led[ListOfLeds[i]].Val;
Led[ListOfLeds[i]].Effect_B = Led[ListOfLeds[i]].Effect;
Led[ListOfLeds[i]].Inc_B = Led[ListOfLeds[i]].Inc;
}
Led[ListOfLeds[i]].Hue = HUE;
Led[ListOfLeds[i]].Sat = 0;
Led[ListOfLeds[i]].Val = 0;
Led[ListOfLeds[i]].Effect = EFFECT;
Led[ListOfLeds[i]].Inc = 0;
Led[ListOfLeds[i]].Active = true;
if ((EFFECT==9 || EFFECT==10) && i>=1) {Led[ListOfLeds[i]].Active = false;}
if (TYPE=="B") {
Led[ListOfLeds[i]].Default = true;
} else {
Led[ListOfLeds[i]].Default = false;
Led[i].Rep = 3;
}
}
}
void SETTINGS_LED_EVALUATE() {
for (uint16_t i=0 ; i < sizeof(Led) / sizeof(Led[0]) ; i++) {
if (Led[i].Active) {
if (millis() > Led[i].Timer) {
switch (Led[i].Effect) {
case 0:
EFFECT_OFF(i);
break;
case 1:
EFFECT_ON(i);
break;
case 2: // Fade in
EFFECT_FADEIN(i);
break;
case 3: // Fade out
EFFECT_FADEOUT(i);
break;
case 4: // EFFECT_Pulsate (brightness 0-255)
EFFECT_PULSATE(i);
break;
case 5: // Breath (brightness 100-255)
EFFECT_BREATHE(i);
break;
case 6: // Flash
EFFECT_FLASH(i);
break;
case 7: // Blink
EFFECT_BLINK(i);
break;
case 8: // Hit
EFFECT_HIT(i);
break;
case 9: // Metor
EFFECT_METEOR(i);
break;
case 10: // Metor
EFFECT_TRAIL(i);
break;
default:
break;
}
}
}
}
}
// EFFECTS
void EFFECT_BLINK(uint16_t i) { // 7
if (Led[i].Sat==0 && Led[i].Val==0) {
// COM("Set values at start on first time function");
Led[i].Sat = 255;
Led[i].Val = 255;
Led[i].Inc = 1;
Led[i].Rep = 5;
}
if (Led[i].Val == 0) {
Led[i].Val = 255;
} else {
Led[i].Val = 0;
}
uint32_t color = Pixels.ColorHSV(Led[i].Hue, Led[i].Sat, Led[i].Val);
Pixels.setPixelColor(Led[i].Index,color);
Led[i].Timer = millis() + 100;
}
void EFFECT_BREATHE(uint16_t i) { // 5
if (Led[i].Sat==0 && Led[i].Val==0) {
// COM("Set values at start on first time function");
Led[i].Sat = 255;
Led[i].Val = 0;
Led[i].Inc = 1;
}
uint32_t H = Led[i].Hue;
uint8_t S = Led[i].Sat;
uint8_t V = Led[i].Val;
uint8_t I = Led[i].Inc;
V = V + I;
if (V <= 150 || V >= 255) {
I = -I;
if (V <= 150) {V = 150;Led[i].Rep = Led[i].Rep - 1;} else {V = 255;}
}
uint32_t color = Pixels.ColorHSV(H, S, V);
Pixels.setPixelColor(Led[i].Index,color);
// COM("Show pixels");
Led[i].Inc = I;
Led[i].Val = V;
Led[i].Timer = millis() + (1000/FPS);
if (Led[i].Default==false) {
// COM("Effect Repetition evaluaties");
if (Led[i].Rep==0) {// Last repetition handled, fall back to default
// COM("Effect finished");
Led[i].Hue = Led[i].Hue_B;
Led[i].Sat = Led[i].Sat_B;
Led[i].Val = Led[i].Val_B;
Led[i].Inc = Led[i].Inc_B;
Led[i].Effect = Led[i].Effect_B;
Led[i].Default = true;
Led[i].Rep = 0;
Led[i].Hue_B = 0;
Led[i].Sat_B = 0;
Led[i].Val_B = 0;
Led[i].Inc_B = 0;
Led[i].Effect_B = 0;
}
}
}
void EFFECT_FADEIN(uint16_t i) { // 2
if (Led[i].Sat==0 && Led[i].Val==0) {
// COM("Set values at start on first time function");
Led[i].Sat = 255;
Led[i].Val = 0;
Led[i].Inc = 2;
}
uint32_t H = Led[i].Hue;
uint8_t S = Led[i].Sat;
uint8_t V = Led[i].Val;
uint8_t I = Led[i].Inc;
V = V + I;
// COM(String(V));
if (V >= 253) {
Led[i].Rep = Led[i].Rep - 1;
}
uint32_t color = Pixels.ColorHSV(H, S, V);
Pixels.setPixelColor(Led[i].Index,color);
// COM("Show pixels");
Led[i].Inc = I;
Led[i].Val = V;
Led[i].Timer = millis() + (1000/FPS);
if (Led[i].Default==false) {
// COM("Effect Repetition evaluaties");
if (Led[i].Rep==0) {// Last repetition handled, fall back to default
// COM("Effect finished");
Led[i].Hue = Led[i].Hue_B;
Led[i].Sat = Led[i].Sat_B;
Led[i].Val = Led[i].Val_B;
Led[i].Inc = Led[i].Inc_B;
Led[i].Effect = Led[i].Effect_B;
Led[i].Default = true;
Led[i].Rep = 0;
Led[i].Hue_B = 0;
Led[i].Sat_B = 0;
Led[i].Val_B = 0;
Led[i].Inc_B = 0;
Led[i].Effect_B = 0;
}
}
}
void EFFECT_FADEOUT(uint16_t i) { // 3
if (Led[i].Sat==0 && Led[i].Val==0) {
// COM("Set values at start on first time function");
Led[i].Sat = 255;
Led[i].Val = 255;
Led[i].Inc = 2;
}
uint32_t H = Led[i].Hue;
uint8_t S = Led[i].Sat;
uint8_t V = Led[i].Val;
uint8_t I = Led[i].Inc;
V = V - I;
// COM(String(V));
if (V <= 1) {
Led[i].Rep = Led[i].Rep - 1;
}
uint32_t color = Pixels.ColorHSV(H, S, V);
Pixels.setPixelColor(Led[i].Index,color);
// COM("Show pixels");
Led[i].Inc = I;
Led[i].Val = V;
Led[i].Timer = millis() + (1000/FPS);
if (Led[i].Default==false) {
// COM("Effect Repetition evaluaties");
if (Led[i].Rep==0) {// Last repetition handled, fall back to default
// COM("Effect finished");
Led[i].Hue = Led[i].Hue_B;
Led[i].Sat = Led[i].Sat_B;
Led[i].Val = Led[i].Val_B;
Led[i].Inc = Led[i].Inc_B;
Led[i].Effect = Led[i].Effect_B;
Led[i].Default = true;
Led[i].Rep = 0;
Led[i].Hue_B = 0;
Led[i].Sat_B = 0;
Led[i].Val_B = 0;
Led[i].Inc_B = 0;
Led[i].Effect_B = 0;
}
}
}
void EFFECT_FLASH(uint16_t i) { // 6
if (Led[i].Sat==0 && Led[i].Val==0) {
// COM("Set values at start on first time function");
Led[i].Hue = Led[i].Hue;
Led[i].Sat = 255;
Led[i].Val = 255;
Led[i].Inc = 5;
Led[i].Rep = 2;
}
if (Led[i].Rep == 2) {
Led[i].Timer = millis() + 100;
Led[i].Rep = 1;
} else
if (Led[i].Rep == 1) {
Led[i].Timer = millis() + (1000/FPS);
Led[i].Val = Led[i].Val - Led[i].Inc;
if (Led[i].Val <= 0) {Led[i].Rep = 0;}
}
uint32_t color = Pixels.ColorHSV(Led[i].Hue, Led[i].Sat, Led[i].Val);
Pixels.setPixelColor(Led[i].Index,color);
if (Led[i].Default==false) {
if (Led[i].Rep==0) {// Last repetition handled, fall back to default
Led[i].Hue = Led[i].Hue_B;
Led[i].Sat = Led[i].Sat_B;
Led[i].Val = Led[i].Val_B;
Led[i].Inc = Led[i].Inc_B;
Led[i].Effect = Led[i].Effect_B;
Led[i].Default = true;
Led[i].Rep = 0;
Led[i].Hue_B = 0;
Led[i].Sat_B = 0;
Led[i].Val_B = 0;
Led[i].Inc_B = 0;
Led[i].Effect_B = 0;
}
}
}
void EFFECT_HIT(uint16_t i) { // 8
if (Led[i].Sat==0 && Led[i].Val==0) {
// COM("Set values at start on first time function");
Led[i].Sat = 255;
Led[i].Val = 0;
Led[i].Rep = 6;
}
if (Led[i].Val==0) {Led[i].Val = 255;} else {Led[i].Val = 0;Led[i].Rep = Led[i].Rep - 1;}
if (Led[i].Rep >= 2) {
Led[i].Timer = millis() + 50;
} else
if (Led[i].Rep == 1) {
EFFECT_ON(i);
Led[i].Active = false;
}
uint32_t color = Pixels.ColorHSV(Led[i].Hue, Led[i].Sat, Led[i].Val);
Pixels.setPixelColor(Led[i].Index,color);
}
void EFFECT_METEOR(uint16_t i) { // 9
if (Led[i].Sat==0 && Led[i].Val==0) {
// COM("Set values at start on first time function");
Led[i].Hue = Led[i].Hue;
Led[i].Sat = 255;
Led[i].Val = 255;
Led[i].Inc = 5;
Led[i].Rep = 10;
}
if (Led[i].Val >= 225 && Led[i].Val <= (225 + Led[i].Inc)) { // One time check for followup led
if (i < (sizeof(Led)/sizeof(Led[0]))) {
Led[i+1].Active = true;
} else {
COM("There's no more led's!, check if the first has to be set");
}
} else
if (Led[i].Val<=2) {
if (Led[i].Default==false) {
Led[i].Hue = Led[i].Hue_B;
Led[i].Sat = Led[i].Sat_B;
Led[i].Val = Led[i].Val_B;
Led[i].Inc = Led[i].Inc_B;
Led[i].Effect = Led[i].Effect_B;
Led[i].Default = true;
Led[i].Rep = 0;
Led[i].Hue_B = 0;
Led[i].Sat_B = 0;
Led[i].Val_B = 0;
Led[i].Inc_B = 0;
Led[i].Effect_B = 0;
} else {
Led[i].Val = 255;
}
}
Led[i].Val = Led[i].Val - Led[i].Inc;
Led[i].Timer = millis() + 25;
uint32_t color = Pixels.ColorHSV(Led[i].Hue, Led[i].Sat, Led[i].Val);
Pixels.setPixelColor(Led[i].Index,color);
}
void EFFECT_OFF(uint16_t i) { // 0
Led[i].Hue = 0;
Led[i].Sat = 0;
Led[i].Val = 0;
Led[i].Inc = 0;
uint32_t color = Pixels.ColorHSV(Led[i].Hue, Led[i].Sat, Led[i].Val);
Pixels.setPixelColor(Led[i].Index,color);
Led[i].Active = false;
}
void EFFECT_ON(uint16_t i) { // 1
Led[i].Sat = 255;
Led[i].Val = 255;
uint32_t color = Pixels.ColorHSV(Led[i].Hue, Led[i].Sat, Led[i].Val);
Pixels.setPixelColor(Led[i].Index,color);
Led[i].Active = false;
}
void EFFECT_PULSATE(uint16_t i) { // 4
if (Led[i].Sat==0 && Led[i].Val==0) {
// COM("Set values at start on first time function");
Led[i].Sat = 255;
Led[i].Val = 0;
Led[i].Inc = 5;
}
uint32_t H = Led[i].Hue;
uint8_t S = Led[i].Sat;
uint8_t V = Led[i].Val;
uint8_t I = Led[i].Inc;
V = V + I;
if (V <= 0 || V >= 255) {
I = -I;
if (V <= 0) {V = 0;Led[i].Rep = Led[i].Rep - 1;} else {V = 255;}
}
uint32_t color = Pixels.ColorHSV(H, S, V);
Pixels.setPixelColor(Led[i].Index,color);
Led[i].Inc = I;
Led[i].Val = V;
Led[i].Timer = millis() + (1000/FPS);
if (Led[i].Default==false) {
// COM("Effect Repetition evaluaties");
if (Led[i].Rep==0) {// Last repetition handled, fall back to default
// COM("Effect finished");
Led[i].Hue = Led[i].Hue_B;
Led[i].Sat = Led[i].Sat_B;
Led[i].Val = Led[i].Val_B;
Led[i].Inc = Led[i].Inc_B;
Led[i].Effect = Led[i].Effect_B;
Led[i].Default = true;
Led[i].Rep = 0;
Led[i].Hue_B = 0;
Led[i].Sat_B = 0;
Led[i].Val_B = 0;
Led[i].Inc_B = 0;
Led[i].Effect_B = 0;
}
}
}
void EFFECT_TRAIL(uint16_t i) { // 10
if (Led[i].Sat==0 && Led[i].Val==0) {
// COM("Set values at start on first time function");
Led[i].Hue = Led[i].Hue;
Led[i].Sat = 255;
Led[i].Val = 0;
Led[i].Inc = 5;
Led[i].Rep = 1;
}
if (Led[i].Val==0) {
Led[i].Val=255;
} else {
Led[i].Val=0;
Led[i+1].Active = true;
}
uint32_t color = Pixels.ColorHSV(Led[i].Hue, Led[i].Sat, Led[i].Val);
Pixels.setPixelColor(Led[i].Index,color);
if (Led[i].Val==0 && Led[i].Default == false) {Led[i].Rep = Led[i].Rep - 1;}
Led[i].Timer = millis() + (BLINK / 2);
if (Led[i].Default==false) {
// COM("Effect Repetition evaluaties");
if (Led[i].Rep==0) {// Last repetition handled, fall back to default
// COM("Effect finished");
Led[i].Hue = Led[i].Hue_B;
Led[i].Sat = Led[i].Sat_B;
Led[i].Val = Led[i].Val_B;
Led[i].Inc = Led[i].Inc_B;
Led[i].Effect = Led[i].Effect_B;
Led[i].Default = true;
Led[i].Rep = 0;
Led[i].Hue_B = 0;
Led[i].Sat_B = 0;
Led[i].Val_B = 0;
Led[i].Inc_B = 0;
Led[i].Effect_B = 0;
}
}
}
void COM(String T) {
if (DEBUG) {
Serial.println(T);
}
}
void SHOW_STARTUP() {
COM("Lightshow at startup");
PHASE = "STARTUP";
for (uint16_t i=0 ; i < sizeof(Led) / sizeof(Led[0]) ; i++) {
Led[i].Effect = 6;
Led[i].Active = true;
Led[i].Hue = 43690;
Led[i].Sat = 255;
Led[i].Val = 255;
Led[i].Inc = 5;
Led[i].Rep = 2;
Led[i].Default = false;
// uint32_t color = Pixels.ColorHSV(Led[i].Hue, Led[i].Sat, Led[i].Val);
// Pixels.setPixelColor(Led[i].Index,color);
if (Led[i].Rep==0) { PHASE="";}
}
}
void SHOW_ATTRACT() {
PHASE = "ATTRACT";
if (EFFECT_COUNTER==0) {
SHOW_RADAR_STEP();
} else {
COM("Radar show ended");
PHASE = "";
}
}
void SHOW_PASSIVE() {
}
void SHOW_KILLTHELIGHTS() {
Pixels.clear();
Pixels.show();
}
void SHOW_RADAR_STEP() {
static float radarHoek = 0;
static int rondjesTeller = 0;
if (rondjesTeller >= 5) {
COM("Teller=" + String(rondjesTeller));
SHOW_KILLTHELIGHTS();
EFFECT_COUNTER ++; // Signaal naar de rest van de code
radarHoek = 0;
rondjesTeller = 0;
COM("Teller=" + String(rondjesTeller));
} else {
radarHoek += 0.1;
if (radarHoek >= 6.28) {
radarHoek = 0;
rondjesTeller++;
COM("Rondjesteller!");
}
for (uint16_t i=0 ; i < sizeof(Led) / sizeof(Led[0]) ; i++) {
float hoekVanLed = atan2(Led[i].Y - 50, Led[i].X - 30);
if (hoekVanLed < 0) hoekVanLed += 6.28;
float verschil = abs(radarHoek - hoekVanLed);
// COM("verschil=" + String(verschil));
if (verschil > 3.14) verschil = 6.28 - verschil;
if (verschil < 0.1) {
Led[i].Val = 255;
Led[i].Hue = 40000; // Bijv. Blauwachtig (uint16_t)
} else {
// Fade effect (zorg dat de leds langzaam dimmen)
if (Led[i].Val > 2) Led[i].Val -= 10;
}
uint32_t color = Pixels.ColorHSV(Led[i].Hue, Led[i].Sat, Led[i].Val);
Pixels.setPixelColor(Led[i].Index,color);
}
}
}