Skip to content

Commit d22d647

Browse files
committed
Debounce power led on state
1 parent 1e9cd5f commit d22d647

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

server/server.ino

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
55
IPAddress ip(192, 168, 0, 10);
66
EthernetServer server(80);
7+
long delayStart;
78

89
const int IN_PIN_POWER_LED = 7;
910
const int OUT_PIN_POWER = 8, OUT_PIN_RESET = 9;
11+
int POWER_LED_OFF_DELAY = 3000; // ms
1012

1113
// Commands
1214
bool powerOn, standBy, reset, kill;
@@ -19,6 +21,7 @@ void setup() {
1921
server.begin();
2022
Serial.print("Server started at ");
2123
Serial.println(Ethernet.localIP());
24+
delayStart = millis();
2225

2326
// SD card
2427
Serial.println("Initializing SD card...");
@@ -43,9 +46,11 @@ void setup() {
4346

4447
void loop() {
4548
// Read inputs
46-
if(digitalRead(IN_PIN_POWER_LED) == 0)
49+
if(digitalRead(IN_PIN_POWER_LED) == 0) {
4750
powerLed = true;
48-
else
51+
delayStart = millis();
52+
}
53+
else if(millis() - delayStart > POWER_LED_OFF_DELAY)
4954
powerLed = false;
5055

5156
// Server

0 commit comments

Comments
 (0)