Explorar el Código

more modes

master
gituser hace 1 mes
padre
commit
e1fca86d7e
Se han modificado 6 ficheros con 127 adiciones y 32 borrados
  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 Ver fichero

connectStart = millis(); connectStart = millis();
setState(STATE_CONNECTING); setState(STATE_CONNECTING);
} }

driveLEDStrip();
} }


void handleError() { void handleError() {
Serial.println(":81/"); 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 ---------- // ---------- SETUP ----------
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);

+ 4
- 4
LEDModes.h Ver fichero

#include <string.h> #include <string.h>


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


static LEDModes parseMode(const char *mode) { static LEDModes parseMode(const char *mode) {

+ 96
- 25
LEDStripManager.cpp Ver fichero

pinMode(LED_STRIP_DATA_PIN, OUTPUT); pinMode(LED_STRIP_DATA_PIN, OUTPUT);


digitalWrite(LED_STRIP_POWER_PIN, HIGH); // LED zunächst EIN digitalWrite(LED_STRIP_POWER_PIN, HIGH); // LED zunächst EIN
digitalWrite(LED_STRIP_DATA_PIN, HIGH);


Config cfg = configManager.getConfig(); Config cfg = configManager.getConfig();


strip.clear(); strip.clear();
strip.show(); // Setzt alle LEDs auf "aus" 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() { void LEDStripManager::clear() {


void LEDStripManager::on() { void LEDStripManager::on() {
Serial.println("LEDStripManager LED ON"); Serial.println("LEDStripManager LED ON");

digitalWrite(LED_STRIP_POWER_PIN, HIGH);
delay(50);
digitalWrite(LED_STRIP_DATA_PIN, HIGH);
delay(50);

begin(); begin();
} }


cfg.mode = mode; cfg.mode = mode;
configManager.saveConfig(cfg); 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) { void LEDStripManager::onColorChange(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) {
this->setBrightness(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; pos = 255 - pos;


if (pos < 85) { if (pos < 85) {
return strip.Color(pos * 3, 255 - pos * 3, 0); 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++) { for (uint16_t i = 0; i < strip.numPixels(); i++) {
uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
} }


strip.show(); 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 Ver fichero



void setAll(uint8_t red, uint8_t green, uint8_t blue, uint8_t white); 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); void onModeChange(LEDModes mode);


ConfigManager &configManager; ConfigManager &configManager;


uint32_t wheel(uint8_t pos); uint32_t wheel(uint8_t pos);

uint32_t firstPixelHue = 0;
}; };


#endif #endif

+ 0
- 1
States.h Ver fichero

STATE_CONNECTING, STATE_CONNECTING,
STATE_STA_MODE, STATE_STA_MODE,
STATE_ERROR STATE_ERROR

}; };


const char* stateToString(AppState state) { const char* stateToString(AppState state) {

+ 2
- 1
sloeber.ino.cpp Ver fichero

//This is a automatic generated file //This is a automatic generated file
//Please do not modify this file //Please do not modify this file
//If you touch this file your change will be overwritten during the next build //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"
#include "Arduino.h" #include "Arduino.h"
void handleSTAMode() ; void handleSTAMode() ;
void handleError() ; void handleError() ;
void startSTAWebServer() ; void startSTAWebServer() ;
void driveLEDStrip() ;
void setup() ; void setup() ;
void loop() ; void loop() ;



Cargando…
Cancelar
Guardar