boothifier/temporary/Temp/MyNeoPixelBus.cpp

47 lines
1.7 KiB
C++

#include <NeoPixelBus.h>
// Define constants for maximum LEDs
#define MAX_LEDS 300 // Adjust based on your LED requirements
// Wrapper class for dynamic LED strips
class DynamicLedStrip {
private:
void* strip; // Pointer to the NeoPixelBus object
int numLeds; // Number of LEDs
String colorOrder; // Color order (for reference)
public:
DynamicLedStrip() : strip(nullptr), numLeds(0), colorOrder("") {}
// Initialize the LED strip
void initialize(int dataPin, int numLeds, const String& chipType, const String& colorOrder) {
this->numLeds = numLeds;
this->colorOrder = colorOrder;
if (chipType == "WS2812" || chipType == "SK6812") {
if (colorOrder == "GRB") {
strip = new NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod>(numLeds, dataPin);
} else if (colorOrder == "RGB") {
strip = new NeoPixelBus<NeoRgbFeature, Neo800KbpsMethod>(numLeds, dataPin);
} else if (colorOrder == "BGR") {
strip = new NeoPixelBus<NeoBgrFeature, Neo800KbpsMethod>(numLeds, dataPin);
}
}
if (strip) {
static_cast<NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod>*>(strip)->Begin();
} else {
Serial.println("Unsupported chipset or color order!");
}
}
// Set all LEDs to a specific color
void setColor(const RgbColor& color) {
if (strip) {
for (int i = 0; i < numLeds; i++) {
static_cast<NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod>*>(strip)->SetPixelColor(i, color);
}
static_cast<NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod>*>(strip)->Show();
}
}
};