mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-05-18 21:55:34 +00:00
made the led work
in a rather bad way...
This commit is contained in:
parent
1dc5587893
commit
4ebefde13f
1 changed files with 30 additions and 12 deletions
42
src/main.cpp
42
src/main.cpp
|
@ -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,16 +103,20 @@ void updateTimer(int interval_ms)
|
||||||
|
|
||||||
void updateLed() // TODO: callback for timer
|
void updateLed() // TODO: callback for timer
|
||||||
{
|
{
|
||||||
led_config = getBlinkingConfig(status);
|
if (millis() - lastMills >= led_config.interval_ms)
|
||||||
if (led_config.is_blinking)
|
|
||||||
{
|
{
|
||||||
led_on = !led_on;
|
lastMills = millis();
|
||||||
analogWrite(PIN_LED, led_on ? led_config.brightness : 0);
|
led_config = getBlinkingConfig(status);
|
||||||
}
|
if (led_config.is_blinking)
|
||||||
else
|
{
|
||||||
{
|
led_on = !led_on;
|
||||||
analogWrite(PIN_LED, led_config.brightness);
|
analogWrite(PIN_LED, led_on ? led_config.brightness : 0);
|
||||||
return;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
analogWrite(PIN_LED, led_config.brightness);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue