/* * LEDStripManager.cpp * * Created on: 19.06.2026 * Author: FSmilari */ #include "LEDStripManager.h" /* * Constructor */ LEDStripManager::LEDStripManager(uint16_t numLeds, uint8_t pin) : strip(numLeds, pin, NEO_GRBW + NEO_KHZ800) { } /* * Destructor */ LEDStripManager::~LEDStripManager() { } void LEDStripManager::begin() { pinMode(LED_STRIP_POWER_PIN, OUTPUT); pinMode(LED_STRIP_DATA_PIN, OUTPUT); digitalWrite(LED_STRIP_POWER_PIN, HIGH); // LED zunächst EIN strip.begin(); // Initialisiert den NeoPixel-Streifen strip.clear(); strip.show(); // Setzt alle LEDs auf "aus" strip.setBrightness(255); // Helligkeit (0 bis 255) // Setzt die erste LED (Index 0) auf rotes Licht (Rot, Grün, Blau, Weiss) strip.setPixelColor(0, strip.Color(255, 0, 0, 0)); // Setzt die zweite LED auf grün strip.setPixelColor(1, strip.Color(0, 255, 0, 0)); strip.setPixelColor(2, strip.Color(0, 0, 255, 0)); strip.setPixelColor(3, strip.Color(0, 0, 0, 255)); // Schickt die Farbinformationen zum LED-Streifen show(); } void LEDStripManager::clear() { strip.clear(); } void LEDStripManager::show() { strip.show(); } void LEDStripManager::on() { Serial.println("LEDStripManager LED ON"); digitalWrite(LED_STRIP_POWER_PIN, HIGH); delay(50); digitalWrite(LED_STRIP_DATA_PIN, HIGH); delay(50); strip.begin(); strip.show(); // TODO: Load the state from the eeprom strip.setPixelColor(0, strip.Color(255, 0, 0, 0)); strip.setPixelColor(1, strip.Color(0, 255, 0, 0)); strip.setPixelColor(2, strip.Color(0, 0, 255, 0)); strip.setPixelColor(3, strip.Color(0, 0, 0, 255)); strip.show(); } void LEDStripManager::off() { Serial.println("LEDStripManager LED OFF"); clear(); show(); delay(50); digitalWrite(LED_STRIP_POWER_PIN, LOW); // LED zunächst AUS digitalWrite(LED_STRIP_DATA_PIN, LOW); } void LEDStripManager::setBrightness(uint8_t brightness) { strip.setBrightness(brightness); } void LEDStripManager::setPixel(uint16_t index, uint8_t red, uint8_t green, uint8_t blue) { if (index >= strip.numPixels()) { return; } strip.setPixelColor(index, strip.Color(red, green, blue)); } void LEDStripManager::setAll(uint8_t red, uint8_t green, uint8_t blue) { for (uint16_t i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, strip.Color(red, green, blue)); } strip.show(); } uint32_t LEDStripManager::wheel(uint8_t pos) { pos = 255 - pos; if (pos < 85) { return strip.Color(255 - pos * 3, 0, pos * 3); } if (pos < 170) { pos -= 85; return strip.Color(0, pos * 3, 255 - pos * 3); } pos -= 170; return strip.Color(pos * 3, 255 - pos * 3, 0); } void LEDStripManager::rainbow(uint8_t wait) { for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) { for (uint16_t i = 0; i < strip.numPixels(); i++) { uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); } strip.show(); delay(wait); } }