So I'm quite new to the whole Arduino coding but constructed a sketch that does work, but I think it doesn't work properly. So I'd love to get some advice on how to improve it.
This script is currently running on a Wemos ESP8266 chip attached to a 1 meter WS2812 144 LED strip.
My questions:
The loop is set to break when fadein is higher then 254. When I try to break it at
fadein == 255
the loop doesn't work anymore as it the fadein value directly jumps to 255. Why?When I set the delay to zero the led flicker due to too fast updating. however, this flickering continues even after the for loop is broken, which makes me conclude that the for loop is still running even when the break is applied.
Of course this is no longer an issue when the delay is set higher (as it is supposed to be) but it still seems a waste of processing power to keep the for loop active while it's not doing anything new anymore how can i completely stop the loop from being executed?
How can this be done differently / more effective?
The code
#define FASTLED_ALLOW_INTERRUPTS 0 //fix jitter in led strip
#include <FastLED.h> //add fastled lib
#define NUM_LEDS 144 //set number of leds
#define DATA_PIN D4 //set data pin leds
CRGB ledStrip[NUM_LEDS]; //init led strip
int fadeIn = 8; //init fade in counter
int led = 0; //init led counter
void setup() {
Serial.begin(115200); //setup comm channel
FastLED.addLeds<WS2811,DATA_PIN, RGB>(ledStrip, NUM_LEDS); //setup ledstrip config
}
void loop()
{
for (int led = 0; led < NUM_LEDS; led++) { //move led up the strip till max count is reached
ledStrip[led] = CHSV( 0+led*1.77, 255, 225); //set animated led hue value to make a rainbow
FastLED.show(); //show led color
ledStrip[led] = CHSV( 0+led*1.77, 255, fadeIn); //set non animated led hue to same hue value while increasing the fade value
delay(3);
if (fadeIn > 254) { //if the fadeIn value exceed 254
break; //stop led animation
}
}
if (led = 144 && fadeIn < 254) { //when the 144th led is reached and the fadein value is less then 255
fadeIn+=16; //increase fadeIn value with 16
}
if (led = 144 && fadeIn < 255) { //when the 144th led is reached and fadeIn is smaller then 255 show debug messages
Serial.println(led); //print led counter value
Serial.println(fadeIn); //print fadein value
}
if (fadeIn > 255) { //if the fadeIn value exceed 255
fadeIn = 255; //clamp fadeIn value to 255
}
}