// https://wokwi.com/projects/410037772389117953
// https://forum.arduino.cc/t/millis-instead-of-delay-on-array-of-ledstrip/1304862/89?u=davex
#include "FastLED.h"
#define NUM_LEDS1 7
#define DATA_PIN1 2
CRGB array_LED_sconce [NUM_LEDS1];
uint32_t interval = 1000, timeout;
int ledBlink[] = {1, 3, 5, 0, 2, 4, 6};
int ii;
void setup()
{
FastLED.addLeds<WS2812B, DATA_PIN1, GRB>(array_LED_sconce, NUM_LEDS1);
FastLED.setBrightness(255);
Serial.begin(115200);
pinMode(13,OUTPUT);
pinMode(3,INPUT_PULLUP);
}
void loop()
{
wiperNB();
//func_up();
// do something else
//func_down();
// do something else
somethingElse();
}
void somethingElse(){
digitalWrite(13,!digitalRead(3));
}
void wiperNB() {
if (millis() - timeout > interval) { // wait for interval
timeout += interval; // restart the "lap" timer
switch (ii) {
case 0 ... 6: // wiping up
ledOnProcessing(ledBlink[ii]);
break;
case 7:
case 15:
allLedsOff();
break;
case 8 ... 14: // wiping down
{
const int LastLedIndex = 6;
int upwardStep = ii - 8;
int ledToChange = LastLedIndex - upwardStep;
ledOnProcessing(ledBlink[ledToChange]);
}
break;
default:
Serial.print(ii);
;
}
++ii; // prepare for next step
if (ii > 15) { // move to next cycle
ii = 0;
}
FastLED.show();
}
}
void ledOnProcessing(int ii) {
array_LED_sconce[ii] = CHSV(50, 250, 250);
}
void allLedsOff() {
fill_solid(array_LED_sconce, NUM_LEDS1, CHSV(0, 0, 0));
}
void func_up()
{
fill_solid(array_LED_sconce, NUM_LEDS1, CHSV(0, 0, 0));
for (int i = 0; i < NUM_LEDS1; i ++)
{
array_LED_sconce [i] = CHSV(50, 250, 250);
FastLED.delay(interval);
FastLED.show();
}
}
void func_down()
{
fill_solid(array_LED_sconce, NUM_LEDS1, CHSV(0, 0, 0));
for (int i = NUM_LEDS1 - 1; i > -1; i--)
{
array_LED_sconce [i] = CHSV(50, 50, 50);
FastLED.delay(interval);
FastLED.show();
}
}