-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggleLed.ino
More file actions
36 lines (28 loc) · 749 Bytes
/
ToggleLed.ino
File metadata and controls
36 lines (28 loc) · 749 Bytes
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
#include <SoftTimers.h>
#define LED_PIN 13
/**************************************************
*Every second, toggle a LED pin.
**************************************************/
SoftTimer togglePinTimer; //millisecond timer
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
//update timers
togglePinTimer.setTimeOutTime(1000); // every 1 second.
//start counting
togglePinTimer.reset();
}
void loop() {
unsigned long loopCount = togglePinTimer.getLoopCount();
bool pinHigh = ((loopCount % 2) == 0); //using 0 to get pin HIGH at the beginning of the sketch
if (pinHigh)
{
//turn ON the LED
digitalWrite(LED_PIN, HIGH);
}
else
{
//turn OFF the LED
digitalWrite(LED_PIN, LOW);
}
}