Hey all.
Im trying to setup a really simple FastLED sketch with 12 WS2812B leds in a ring.
Im trying to make it visually look like a smooth rotation of 3 LED's. With the middle LED being the brightest/Highest contrast. Colour isn't much of a concern right now but i'd like to be able to change it later.
I've read elsewhere FastLED does not like exceeding the number of LEDs you define. So i tried to create a for loop to compensate for the start and end of each cycle. But i cannot get LED 12 to light at start or LED 0 to light at the end.
I've been trying to get this working and i can't see what i've done wrong.
Simple help would be appreciated.
#include <FastLED.h>
#define DATA_PIN 5
#define NUM_LEDS 12
int DELAYTIME = 300;
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; CurrentLED++) {
if (CurrentLED == 0){
PreviousLED = 12;
}
else {
PreviousLED = CurrentLED - 1;
}
if (CurrentLED == 12){
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!!");
}
EDIT: BELOW IS THE FINAL WORKING SCRIPT.
Change Lightwidth to the number of LED's you want circling.
#include "FastLED.h"
#define NUM_LEDS 12 // Enter the total number of LEDs on the strip
#define PIN 5 // LED signal Pin
int LightWidth = 3; //Set the number of active LED's
int delayDuration = 400;
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(9600);
FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 500); // limit power of LED strip to 5V, 500mA
FastLED.clear(); // Init LEDs to "off"
}
void loop() {
//////(int red, int green, int blue, int LightWidth, int delayDuration)
Beacon(204, 136, 0, LightWidth, delayDuration);
}
void Beacon(int red, int green, int blue, int LightWidth, int delayDuration){
int LightWidthFix = LightWidth - 1;
for(int i = 0; i <= ((NUM_LEDS -LightWidth) + LightWidthFix); i++) {
FastLED.clear();
FastLED.show();
///////////////////////////////////////////Create Primary Leading LED/////////////////////////////////////////////////
leds[i].setRGB(red/10, green/10, blue/10);
///////////////////////////////////////////Create Primary Leading LED/////////////////////////////////////////////////
///////////////////////////////////////////Create second Trailing LED/////////////////////////////////////////////////
int j;
if (i < LightWidthFix ) {
j = (i + NUM_LEDS) - LightWidthFix;
leds[j].setRGB(red/10, green/10, blue/10);
}
else{
j = i -LightWidthFix;
leds[j].setRGB(red/10, green/10, blue/10);
}
///////////////////////////////////////////Create second Trailing LED/////////////////////////////////////////////////
///////////////////////////////////////////Fill from Low fix/////////////////////////////////////////////////
if ((i>0)&&(i<LightWidthFix)){
Serial.println("FILL LOW");
for (int l = i; l >= 0; l--) {
leds[l].setRGB(red, green, blue);
}
}
///////////////////////////////////////////Fill from Low fix/////////////////////////////////////////////////
///////////////////////////////////////////Fill To High fix//////////////////////////////////////////////////
if ((j<NUM_LEDS)&&(j>(NUM_LEDS-LightWidth))){
Serial.println("FILL HIGH");
for (int l = j; l < NUM_LEDS; l++) {
leds[l].setRGB(red, green, blue);
}
}
///////////////////////////////////////////Fill To High fix//////////////////////////////////////////////////
///////////////////////////////////////////Fill To Main Cycle//////////////////////////////////////////////////
if ((i>=LightWidthFix)&&(j<=(NUM_LEDS-LightWidth))){
Serial.println("FILL MAIN");
for (int t = 0; t <= LightWidthFix; t++){
leds[j+t].setRGB(red, green, blue);
}
}
///////////////////////////////////////////Fill To Main Cycle//////////////////////////////////////////////////
FastLED.show();
delay(delayDuration);
}
}