It is strongly recommended to check the new allocated pointer is not null

Thomas COIN
2020-10-29 14:15:27 +01:00
parent 0eee68753c
commit 0d52695aa9

@@ -39,12 +39,17 @@ void setup() {
...
}
void PixelCountChanged(uint16_t newCount) {
bool PixelCountChanged(uint16_t newCount) {
if (strip != NULL) {
delete strip; // delete the previous dynamically created strip
}
strip = new NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod>(newCount, Pin); // and recreate with new count
if (strip == NULL) {
Serial.println("OUT OF MEMORY");
return false;
}
strip->Begin();
return true;
}
void loop() {