I'm trying to work with the FastLed libraries and i'm controlling a Led Stip via a WEMOS D1 MINI based on the ESP8266, what I'm trying to achieve is to jump from fastled animation to another one..those animations are inside a While loop as shown in the code, so , i thought to just read again from the serial in order to change an integer to exit those while loop, but for some reason is not working as expected. Anyone can help me to uderstand?
CRGB leds[NUM_LEDS];
int incomingByte = 0;
int exit = 0;
void setup() {
Serial.begin(115200);
delay( 1000 );
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
}
void loop()
{
while (Serial.available()>0)
{
Serial.write("Serial.available");
incomingByte = Serial.read();
switch (incomingByte)
{
case '1':
GreenYellow();
break;
case '2':
Sparkle();
break;
}
}
}
void Sparkle() {
while(exit = 0){
int Pixel = random(NUM_LEDS);
setPixel(Pixel,random(255),random(255),random(255));
FastLED.show();
delay(50);
setPixel(Pixel,0,0,0);
if(Serial.available()>0){
incomingByte = Serial.read();
if(incomingByte != '2'){
exit = 1;
}
}
}
}
}
void GreenYellow()
{
for(int x =0; x< NUM_LEDS/2; x++){
leds[x]= CRGB::Green;
}
for(int x =NUM_LEDS/2; x< NUM_LEDS; x++){
leds[x]= CRGB::Yellow;
}
FastLED.show();
}
void setPixel(int Pixel, byte red, byte green, byte blue)
{
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
FastLED.show();
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
FastLED.show();
}
Bonus question: I read that there is no thread programming on the ESP2866 via the Arduino IDE, am I right?