made the led work

in a rather bad way...
This commit is contained in:
Hendrik Rauh 2025-04-24 21:40:23 +02:00
parent 1dc5587893
commit 4ebefde13f

View file

@ -37,6 +37,7 @@ byte dmx2_data[DMX_PACKET_SIZE];
uint8_t brightness_led = 20; uint8_t brightness_led = 20;
bool led_on = true; bool led_on = true;
double lastMills = 0;
// Ethernet stuff // Ethernet stuff
#define ETH_SCK 36 #define ETH_SCK 36
@ -102,6 +103,9 @@ void updateTimer(int interval_ms)
void updateLed() // TODO: callback for timer void updateLed() // TODO: callback for timer
{ {
if (millis() - lastMills >= led_config.interval_ms)
{
lastMills = millis();
led_config = getBlinkingConfig(status); led_config = getBlinkingConfig(status);
if (led_config.is_blinking) if (led_config.is_blinking)
{ {
@ -114,6 +118,7 @@ void updateLed() // TODO: callback for timer
return; return;
} }
} }
}
void setStatus(Status newStatus) void setStatus(Status newStatus)
{ {
@ -155,6 +160,9 @@ void onButtonPress()
void setup() void setup()
{ {
setStatus(Status::Starting); setStatus(Status::Starting);
pinMode(PIN_LED, OUTPUT);
updateLed();
Serial.begin(9600); Serial.begin(9600);
// Get ETH mac // Get ETH mac
@ -182,7 +190,7 @@ void setup()
brightness_led = config.getUInt("led-brightness", DEFAULT_LED_BRIGHTNESS); brightness_led = config.getUInt("led-brightness", DEFAULT_LED_BRIGHTNESS);
bool restartViaButton = config.getBool("restart-via-btn", false); bool restartViaButton = config.getBool("restart-via-btn", false);
config.end(); config.end();
analogWrite(PIN_LED, brightness_led); updateLed();
// Button // Button
pinMode(PIN_BUTTON, INPUT_PULLUP); pinMode(PIN_BUTTON, INPUT_PULLUP);
@ -192,6 +200,7 @@ void setup()
unsigned long startTime = millis(); unsigned long startTime = millis();
while (digitalRead(PIN_BUTTON) == LOW && (millis() - startTime <= 3000)) while (digitalRead(PIN_BUTTON) == LOW && (millis() - startTime <= 3000))
{ {
updateLed();
} }
if (digitalRead(PIN_BUTTON) == LOW) if (digitalRead(PIN_BUTTON) == LOW)
{ {
@ -200,7 +209,11 @@ void setup()
config.clear(); config.clear();
config.end(); config.end();
setStatus(Status::Normal); setStatus(Status::Normal);
delay(2000); unsigned long startTime = millis();
while (millis() - startTime <= 2000)
{
updateLed();
}
} }
} }
@ -213,7 +226,11 @@ void setup()
attachInterrupt(PIN_BUTTON, onButtonPress, FALLING); attachInterrupt(PIN_BUTTON, onButtonPress, FALLING);
// wait for serial monitor // wait for serial monitor
delay(5000); unsigned long startTime = millis();
while (millis() - startTime <= 5000)
{
updateLed();
}
Serial.println("Starting DMX-Interface..."); Serial.println("Starting DMX-Interface...");
config.begin("dmx", true); config.begin("dmx", true);
@ -494,4 +511,5 @@ void loop()
} }
webSocketLoop(); webSocketLoop();
updateLed();
} }