|
|
|
@@ -27,6 +27,7 @@ void LEDStripManager::begin() { |
|
|
|
pinMode(LED_STRIP_DATA_PIN, OUTPUT); |
|
|
|
|
|
|
|
digitalWrite(LED_STRIP_POWER_PIN, HIGH); // LED zunächst EIN |
|
|
|
digitalWrite(LED_STRIP_DATA_PIN, HIGH); |
|
|
|
|
|
|
|
Config cfg = configManager.getConfig(); |
|
|
|
|
|
|
|
@@ -41,20 +42,26 @@ void LEDStripManager::begin() { |
|
|
|
strip.clear(); |
|
|
|
strip.show(); // Setzt alle LEDs auf "aus" |
|
|
|
|
|
|
|
if (cfg.mode == LM_SINGLE_COLOR) { |
|
|
|
strip.setBrightness(cfg.brightness); // Helligkeit (0 bis 255) |
|
|
|
setAll(cfg.color.r, cfg.color.g, cfg.color.b, cfg.color.w); |
|
|
|
} else { |
|
|
|
// 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(); |
|
|
|
switch (cfg.mode) { |
|
|
|
case LM_SINGLE_COLOR: |
|
|
|
this->setBrightness(cfg.brightness); |
|
|
|
setAll(cfg.color.r, cfg.color.g, cfg.color.b, cfg.color.w); |
|
|
|
return; |
|
|
|
case LM_SEGMENTS: |
|
|
|
this->setBrightness(cfg.brightness); |
|
|
|
setSegments(); |
|
|
|
return; |
|
|
|
default: |
|
|
|
// 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(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void LEDStripManager::clear() { |
|
|
|
@@ -67,12 +74,6 @@ void LEDStripManager::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); |
|
|
|
|
|
|
|
begin(); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -110,7 +111,19 @@ void LEDStripManager::onModeChange(LEDModes mode) { |
|
|
|
cfg.mode = mode; |
|
|
|
configManager.saveConfig(cfg); |
|
|
|
|
|
|
|
//TODO: react on mode change on strip |
|
|
|
// Handle only single action modes here. For Animations use loop functions with nonblocking timers |
|
|
|
switch (mode) { |
|
|
|
case LM_SINGLE_COLOR: |
|
|
|
this->setBrightness(cfg.brightness); |
|
|
|
setAll(cfg.color.r, cfg.color.g, cfg.color.b, cfg.color.w); |
|
|
|
return; |
|
|
|
case LM_SEGMENTS: |
|
|
|
this->setBrightness(cfg.brightness); |
|
|
|
setSegments(); |
|
|
|
return; |
|
|
|
default: |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void LEDStripManager::onColorChange(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) { |
|
|
|
@@ -132,8 +145,22 @@ void LEDStripManager::onBrightnessChange(uint8_t brightness) { |
|
|
|
this->setBrightness(brightness); |
|
|
|
} |
|
|
|
|
|
|
|
uint32_t |
|
|
|
LEDStripManager::wheel(uint8_t pos) { |
|
|
|
void LEDStripManager::setSegments() { |
|
|
|
int nbrPixel = strip.numPixels(); |
|
|
|
int third = nbrPixel / 3; |
|
|
|
|
|
|
|
for (int i = 0; i < nbrPixel; i++) { |
|
|
|
if (i < third) |
|
|
|
setPixel(i, 255, 0, 0, 0); |
|
|
|
else if (i < 2 * third) |
|
|
|
setPixel(i, 0, 255, 0, 0); |
|
|
|
else |
|
|
|
setPixel(i, 0, 0, 255, 0); |
|
|
|
} |
|
|
|
show(); |
|
|
|
} |
|
|
|
|
|
|
|
uint32_t LEDStripManager::wheel(uint8_t pos) { |
|
|
|
pos = 255 - pos; |
|
|
|
|
|
|
|
if (pos < 85) { |
|
|
|
@@ -150,14 +177,58 @@ LEDStripManager::wheel(uint8_t pos) { |
|
|
|
return strip.Color(pos * 3, 255 - pos * 3, 0); |
|
|
|
} |
|
|
|
|
|
|
|
void LEDStripManager::rainbow(uint8_t wait) { |
|
|
|
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) { |
|
|
|
void LEDStripManager::rainbow() { |
|
|
|
|
|
|
|
static uint8_t delay = 20; |
|
|
|
static uint32_t lastUpdate = 0; |
|
|
|
|
|
|
|
if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) { |
|
|
|
|
|
|
|
if (millis() - lastUpdate < delay) |
|
|
|
return; |
|
|
|
|
|
|
|
lastUpdate = millis(); |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
firstPixelHue = (firstPixelHue + 256) % 65536; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void LEDStripManager::flash() { |
|
|
|
|
|
|
|
static const uint32_t onMillis = 1000; |
|
|
|
static const uint32_t offMillis = 500; |
|
|
|
|
|
|
|
static bool ledOn = false; |
|
|
|
static uint32_t lastChange = 0; |
|
|
|
|
|
|
|
if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) { |
|
|
|
|
|
|
|
Config cfg = configManager.getConfig(); |
|
|
|
uint32_t now = millis(); |
|
|
|
|
|
|
|
if (ledOn) { |
|
|
|
if (now - lastChange >= onMillis) { |
|
|
|
// LEDs ausschalten |
|
|
|
clear(); |
|
|
|
show(); |
|
|
|
ledOn = false; |
|
|
|
lastChange = now; |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (now - lastChange >= offMillis) { |
|
|
|
// LEDs einschalten |
|
|
|
setAll(cfg.color.r, cfg.color.g, cfg.color.b, cfg.color.w); |
|
|
|
ledOn = true; |
|
|
|
lastChange = now; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|