Browse Source

all led modes

master
gituser 1 month ago
parent
commit
eb2e08b790
5 changed files with 121 additions and 4 deletions
  1. 6
    0
      LEDLamp.ino
  2. 2
    2
      LEDModes.h
  3. 108
    1
      LEDStripManager.cpp
  4. 4
    0
      LEDStripManager.h
  5. 1
    1
      sloeber.ino.cpp

+ 6
- 0
LEDLamp.ino View File

@@ -283,6 +283,12 @@ void driveLEDStrip() {
case LM_FLASH:
ledMngr.flash();
break;
case LM_SPECTRAL:
ledMngr.doSpectral();
break;
case LM_FADING:
ledMngr.fade();
break;
default:
break;
}

+ 2
- 2
LEDModes.h View File

@@ -13,8 +13,8 @@
enum LEDModes {
LM_SINGLE_COLOR = 0, // done
LM_RAINBOW = 1, // done
LM_SPECTRAL = 2,
LM_FADING = 3,
LM_SPECTRAL = 2, // done
LM_FADING = 3, // done
LM_FLASH = 4, // done
LM_SEGMENTS = 5 // done
};

+ 108
- 1
LEDStripManager.cpp View File

@@ -200,6 +200,114 @@ void LEDStripManager::rainbow() {
}
}

void LEDStripManager::doSpectral() {
static uint16_t hue = 0;
static uint32_t lastUpdate = 0;

const uint32_t stepTime = 10000; // 5 s bis zur nächsten Farbe
const uint16_t hueStep = 65536 / 6; // Abstand der Hauptfarben

if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) {

uint32_t now = millis();

if (now - lastUpdate >= 20) {
lastUpdate = now;

hue += (uint32_t) hueStep * 20 / stepTime;

uint32_t color = strip.gamma32(strip.ColorHSV(hue));

for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, color);
}

strip.show();
}
}
}

void LEDStripManager::fade() {

static const uint8_t colors[][3] = {
{ 255, 0, 0 }, // Rot
{ 255, 32, 0 }, // Orange
{ 255, 110, 0 }, // Gelb
{ 0, 255, 0 }, // Grün
{ 0, 255, 255 }, // Cyan
{ 0, 0, 255 }, // Blau
{ 255, 0, 255 } // Violett
};

enum State {
HOLD,
FADE_OUT,
FADE_IN
};

static State state = HOLD;
static uint8_t currentColor = 0;
static uint32_t stateStart = millis();

const uint32_t holdTime = 5000;
const uint32_t fadeTime = 1000;

if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) {

Config cfg = configManager.getConfig();

uint32_t now = millis();
uint32_t elapsed = now - stateStart;

float brightness = 1.0f;
float maxBrightness = float(cfg.brightness) / 255;

switch (state) {

case HOLD:
brightness = maxBrightness;
if (elapsed >= holdTime) {
state = FADE_OUT;
stateStart = now;
}
break;

case FADE_OUT:
brightness = maxBrightness - (float) elapsed / fadeTime;
if (brightness < 0.0f)
brightness = 0.0f;

if (elapsed >= fadeTime) {
currentColor = (currentColor + 1) % (sizeof(colors) / sizeof(colors[0]));
state = FADE_IN;
stateStart = now;
}
break;

case FADE_IN:
brightness = (float) elapsed / fadeTime;
if (brightness > maxBrightness)
brightness = maxBrightness;

if (elapsed >= fadeTime) {
state = HOLD;
stateStart = now;
}
break;
}

uint8_t r = colors[currentColor][0] * brightness;
uint8_t g = colors[currentColor][1] * brightness;
uint8_t b = colors[currentColor][2] * brightness;

for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(r, g, b));
}

strip.show();
}
}

void LEDStripManager::flash() {

static const uint32_t onMillis = 1000;
@@ -231,4 +339,3 @@ void LEDStripManager::flash() {
}
}
}


+ 4
- 0
LEDStripManager.h View File

@@ -38,6 +38,10 @@ class LEDStripManager {

void flash();

void doSpectral();

void fade();

void onModeChange(LEDModes mode);

void onColorChange(uint8_t red, uint8_t green, uint8_t blue, uint8_t white);

+ 1
- 1
sloeber.ino.cpp View File

@@ -2,7 +2,7 @@
//This is a automatic generated file
//Please do not modify this file
//If you touch this file your change will be overwritten during the next build
//This file has been generated on 2026-06-28 18:20:27
//This file has been generated on 2026-06-29 10:34:17

#include "Arduino.h"
#include "Arduino.h"

Loading…
Cancel
Save