I'm fairly new at writing Arduino code and am confused by a block of code.
When executed, a blue dot travels down the LED strip and eventually loops back to the start.
#include <FastLED.h>
#define NUM_LEDS 150
#define DATA_PIN 4
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
void loop() {
for(int dot = 0; dot < NUM_LEDS; dot++) {
leds[dot] = CRGB::Blue;
FastLED.show();
// clear this led for the next time around the loop
leds[dot] = CRGB::Black;
delay(30);
}
}
Following the void loop logic...
We set the first LED in the array to blue...
We then tell the strip to turn on with the .show()...
We then set the LED to Black... (This is where I'm confused)
And then set a Delay on the function...
Function then iterates the dot variable and continues down the LED strip.
Points of confusion
- When we set the LED to black, we never run another .show() method. How does the strip know to go to black?
- When I set the delay to something crazy like 300000, the blue light appears... waits the delay time.. then turns off and then iterates to the next LED. The behavior I would of expected would of been the light to turn blue... then immediately to black... and then wait for the delay timer.. then iterate to the next LED... I'm not sure how the delay is associated with the
leds[dot] = CRGB::Black;
line.