Hi All,
I've just started mucking around with the FastLED library and some WS2812B LEDs. I'm trying to learn FastLED and obviously part of that is using the Serial functions to help debug and understand example code.
My problem is that as soon as I enable Serial comms with the line Serial.begin(BAUD); (on line 20 of the following code) nothing works! The LEDs light up white and very bright as the code is being uploaded but then just stay that way. If I push the reset button it stays that way, if I unplug the USB cable then plug it back in the LEDs just stay off.
Commenting out the line in question, Serial.begin(BAUD); and uploading again everything works just fine, the LEDs fade through RainbowColors_p as expected.
With Serial.begin(BAUD); being used however the lines that print to the serial monitor are outputting the correct info in a constant stream so I believe the code is looping and running correctly.
lines 47 & 48
Serial.print("colorIndex is -> ");
Serial.println(colorIndex, DEC);
I very much doubt this is a problem with the FastLED library or the Arduino. I'm running this on a Linux box, very new hardware, Fedora 26. I have had the Serial comms working no problems with other code on the same Arduino.
Any Linux/Arduino experts out there willing to help would be great!!
Code is as follows:
#include <FastLED.h>
#define LED_PIN 0 // digital pin to output data
#define NUM_LEDS 8 // number of LEDs in string
#define BRIGHTNESS 32 // can be 0-255
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define BAUD (115200)
CRGB leds[NUM_LEDS]; // This is an array of leds. One item for each led in your strip.
#define UPDATES_PER_SECOND 50
CRGBPalette16 currentPalette;
TBlendType currentBlending;
void setup() {
delay(2000); // power-up safety delay
Serial.begin(BAUD); // setup serial comunication
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
currentBlending = LINEARBLEND;
currentPalette = RainbowColors_p;
static uint8_t startIndex = 0;
startIndex = startIndex + 1; // motion speed
FillLEDsFromPaletteColors(startIndex);
FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
}
void FillLEDsFromPaletteColors(uint8_t colorIndex) {
uint8_t brightness = 255;
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette(currentPalette, colorIndex, brightness, currentBlending);
colorIndex += 3;
Serial.print("colorIndex is -> ");
Serial.println(colorIndex, DEC);
}
}