-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToggleLedAdvanced.ino
56 lines (42 loc) · 1.17 KB
/
ToggleLedAdvanced.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <SoftTimers.h>
#define LED_PIN 13
/**************************************************
* Wait 1 second, turn on a LED for 0.3 second.
**************************************************/
SoftTimer delayTimer; //millisecond timer
SoftTimer ledTimer; //millisecond timer
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
//update timers
delayTimer.setTimeOutTime(1000); // 1 second.
ledTimer.setTimeOutTime(300); // 0.3 second.
//start counting now
delayTimer.reset();
ledTimer.reset();
}
void loop() {
if (!delayTimer.hasTimedOut())
{
Serial.println("waiting...");
//reset LED timer so that is does not time out before delayTimer
ledTimer.reset();
}
//did we waited long enough ?
else if (delayTimer.hasTimedOut() && !ledTimer.hasTimedOut())
{
Serial.println("turning LED ON...");
//turn ON the LED
digitalWrite(LED_PIN, HIGH);
}
//should the LED be turned OFF ?
else if (delayTimer.hasTimedOut() && ledTimer.hasTimedOut())
{
Serial.println("turning LED OFF...");
//turn OFF the LED
digitalWrite(LED_PIN, LOW);
//restart both timers
delayTimer.reset();
ledTimer.reset();
}
}