I'm new to Arduino coding and FastLED. When it comes to coding, I'm a complete novice, however, I've been watching YouTube tutorials to help my knowledge. I have successfully run my code on Wokwi, however, when I upload my code to my Arduino, it uploads without error, yet the WS2812B doesn't run the code correctly and appears to freeze after the first pattern.
The LED strip works just run with my Adafruit code, running a very basic set of patterns I created (different than the below code).
Any help would be greatly appreciated! The code below is what I wrote up in Wokwi and the simulation works flawlessly. The only change when uploading to my Arduino is: NUM_LEDS 135
#include <FastLED.h>
#define NUM_LEDS 16
#define LED_PIN 5
#define BRIGHTNESS 255
#define caseCount 7
CRGB source1[NUM_LEDS];
CRGB source2[NUM_LEDS];
CRGB output[NUM_LEDS];
DEFINE_GRADIENT_PALETTE (christmasBlue_gp) {
0, 0, 0, 255,
64, 0, 0, 135,
127, 255, 255, 255,
191, 0, 0, 135,
255, 0, 0, 255
};
CRGBPalette16 bluePal = christmasBlue_gp;
uint8_t blendAmount = 0;
uint8_t patternCounter = 0;
uint8_t source1Pattern = 0;
uint8_t source2Pattern = 1;
bool useSource1 = false;
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(output, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
EVERY_N_MILLISECONDS(5) {
blend(source1, source2, output, NUM_LEDS, blendAmount);
if (useSource1) {
if (blendAmount < 255) blendAmount++;
} else {
if (blendAmount > 0) blendAmount--;
}
}
EVERY_N_SECONDS(5) {
nextPattern();
}
runPattern(source1Pattern, source1);
runPattern(source2Pattern, source2);
FastLED.show();
}
void nextPattern() {
patternCounter = (patternCounter + 1) % caseCount;
if (useSource1) source1Pattern = patternCounter;
else source2Pattern = patternCounter;
useSource1 = !useSource1;
}
void runPattern(uint8_t pattern, CRGB *LEDArray) {
switch (pattern) {
case 0:
movingDots(LEDArray);
break;
case 1:
whiteFill(LEDArray);
break;
case 2:
greenFill(LEDArray);
break;
case 3:
whiteFill(LEDArray);
break;
case 4:
redFill(LEDArray);
break;
case 5:
greenBlueTwinkle(LEDArray);
break;
case 6:
greenRedSplit(LEDArray);
break;
}
}
void movingDots(CRGB *LEDarray) {
uint16_t posBeat = beatsin16(30, 0, NUM_LEDS -1, 0, 0);
uint16_t posBeat2 = beatsin16(60, 0, NUM_LEDS -1, 0, 0);
uint16_t posBeat3 = beatsin16(25, 0, NUM_LEDS -1, 0, 127);
uint16_t posBeat4 = beatsin16(45, 0, NUM_LEDS -1, 0, 127);
LEDarray[(posBeat + posBeat2) / 2] = CHSV(0, 255, 255);
LEDarray[(posBeat3 + posBeat4) / 2] = CHSV(120, 255, 255);
LEDarray[(posBeat3 + posBeat2) / 2] = CHSV(120, 255, 255);
LEDarray[(posBeat2 + posBeat4) / 2] = CHSV(0, 255, 255);
LEDarray[(posBeat2 + posBeat4 + posBeat) / 3] = CHSV(0, 0, 255);
fadeToBlackBy(LEDarray, NUM_LEDS, 1);
}
void whiteFill(CRGB *LEDarray) {
fill_solid(LEDarray, NUM_LEDS, CRGB::White);
}
void greenFill(CRGB *LEDarray) {
fill_solid(LEDarray, NUM_LEDS, CRGB::Green);
}
void redFill(CRGB *LEDarray) {
fill_solid(LEDarray, NUM_LEDS, CRGB::Red);
}
void greenBlueTwinkle(CRGB *LEDarray) {
EVERY_N_MILLISECONDS(50){
LEDarray[random8(0, NUM_LEDS-1)] = ColorFromPalette(bluePal, random8(), 255, LINEARBLEND);
}
fadeToBlackBy(LEDarray, NUM_LEDS, 1);
FastLED.show();
}
void greenRedSplit(CRGB *LEDarray) {
for(int i = 0; i < NUM_LEDS; i++) {
LEDarray[i] = CHSV(0, 255, 255);
LEDarray[(NUM_LEDS-1-i)] = CHSV(120, 255, 255);
FastLED.show();
delay(100);
LEDarray[i] = CHSV(0, 255, 255);
}
for(int i = NUM_LEDS - 1; i >= 0; i--) {
LEDarray[i] = CHSV(120, 255, 255);
LEDarray[(NUM_LEDS-1-i)] = CHSV(0, 255, 255);
FastLED.show();
delay(100);
LEDarray[i] = CHSV(120, 255, 255);
}
}