I have a pretty simple sketch that crashes, and crashes hard (Platform.io console says "Disconnected (read failed: [Errno 6] Device not configured)" and I need to power off/on the Arduino to continue.
The sketch does not crash and seems to work fine when I use a smaller number of LEDS but crashes after a few seconds when I use a longer number of LEDS. Seems like a strange hardware issue because the sketch looks simple! I have added a lot of Serial.print(ln)'s to verify it is doing what I think it is, and it does... until the crash!
This will run forever, but if I change cNumLeds from 60 to 160 it crashes (and my actual LED strip has 300 LEDs and I use all of them in other sketches).
#include <Arduino.h>
#include <FastLED.h>
const uint16_t cDataPin = 15;
const uint16_t cNumLeds = 60;
CRGB leds[cNumLeds];
void setup() {
Serial.begin(9600);
FastLED.addLeds<WS2812B, cDataPin, GRB>(leds, cNumLeds).setCorrection(TypicalLEDStrip).setDither(true);
FastLED.setBrightness(127);
FastLED.clear();
FastLED.show();
FastLED.delay(100);
}
uint16_t offset = 0;
CRGB colors[] = {CRGB::White, CRGB::Red, CRGB::White, CRGB::Green, CRGB::White, CRGB::Black};
byte numColors = sizeof(colors)/sizeof(colors[0]);
uint32_t cycle = 75;
void loop() {
EVERY_N_MILLISECONDS(cycle) {
for (uint16_t i = 0; i < cNumLeds; i++) {
leds[i] = colors[(i + offset) % numColors];
}
offset = (1 + offset) % cNumLeds;
}
FastLED.show();
}
Any tips for debugging greatly appreciated ! (And apologies in advance for my C++ style, I am a confirmed C programmer trying not to do any damage in C++)