// Forum: https://forum.arduino.cc/t/fastled-visual-looping-issue/1134527/4
// Sketch from post #4
// Sketch made by pathogenex
// This Wokwi project: https://wokwi.com/projects/366625947150023681
#include <FastLED.h>
#define DATA_PIN 5
#define NUM_LEDS 12
int DELAYTIME = 500;
int NextLED;
int CurrentLED;
int PreviousLED;
CRGB leds[NUM_LEDS];
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
}
//----------------------------------------------------------------------------------
void loop() {
for( CurrentLED = 0; CurrentLED <= (NUM_LEDS-1); CurrentLED++) {
if (CurrentLED == 0){
PreviousLED = 11;
}
else {
PreviousLED = CurrentLED - 1;
}
if (CurrentLED == 11){
NextLED = 0;
}
else{
NextLED = CurrentLED +1;
}
Serial.print("PreviousLED :");
Serial.println(PreviousLED);
Serial.print("CurrentLED :");
Serial.println(CurrentLED);
Serial.print("NextLED :");
Serial.println(NextLED);
Serial.println("NEXT-------------");
fill_solid(leds, NUM_LEDS, 0x000000);
leds[PreviousLED] = 0x777040;
leds[CurrentLED] = 0xFFD700;
leds[NextLED] = 0x777040;
delay(10);
FastLED.show();
delay(DELAYTIME);
}
Serial.println("!!LOOP!!");
}