gituser před 1 měsícem
rodič
revize
e1fca86d7e
6 změnil soubory, kde provedl 127 přidání a 32 odebrání
  1. 18
    0
      LEDLamp.ino
  2. 4
    4
      LEDModes.h
  3. 96
    25
      LEDStripManager.cpp
  4. 7
    1
      LEDStripManager.h
  5. 0
    1
      States.h
  6. 2
    1
      sloeber.ino.cpp

+ 18
- 0
LEDLamp.ino Zobrazit soubor

@@ -242,6 +242,8 @@ void handleSTAMode() {
connectStart = millis();
setState(STATE_CONNECTING);
}

driveLEDStrip();
}

void handleError() {
@@ -270,6 +272,22 @@ void startSTAWebServer() {
Serial.println(":81/");
}

void driveLEDStrip() {
Config cfg = configManager.getConfig();

switch (cfg.mode) {
case LM_RAINBOW:
ledMngr.setBrightness(cfg.brightness);
ledMngr.rainbow();
break;
case LM_FLASH:
ledMngr.flash();
break;
default:
break;
}
}

// ---------- SETUP ----------
void setup() {
Serial.begin(115200);

+ 4
- 4
LEDModes.h Zobrazit soubor

@@ -11,12 +11,12 @@
#include <string.h>

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

static LEDModes parseMode(const char *mode) {

+ 96
- 25
LEDStripManager.cpp Zobrazit soubor

@@ -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;
}
}
}
}


+ 7
- 1
LEDStripManager.h Zobrazit soubor

@@ -32,7 +32,11 @@ class LEDStripManager {

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

void rainbow(uint8_t wait);
void rainbow();

void setSegments();

void flash();

void onModeChange(LEDModes mode);

@@ -46,6 +50,8 @@ class LEDStripManager {
ConfigManager &configManager;

uint32_t wheel(uint8_t pos);

uint32_t firstPixelHue = 0;
};

#endif

+ 0
- 1
States.h Zobrazit soubor

@@ -14,7 +14,6 @@ enum AppState {
STATE_CONNECTING,
STATE_STA_MODE,
STATE_ERROR

};

const char* stateToString(AppState state) {

+ 2
- 1
sloeber.ino.cpp Zobrazit soubor

@@ -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-27 09:18:25
//This file has been generated on 2026-06-28 18:20:27

#include "Arduino.h"
#include "Arduino.h"
@@ -32,6 +32,7 @@ void handleAPMode() ;
void handleSTAMode() ;
void handleError() ;
void startSTAWebServer() ;
void driveLEDStrip() ;
void setup() ;
void loop() ;


Načítá se…
Zrušit
Uložit