Skip to content

Commit bc779fd

Browse files
authored
Added Multiple LED control example.
1 parent d2af3d0 commit bc779fd

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <PicoTimer.h>
2+
3+
// Pin Definitions
4+
const int LED_STATUS = LED_BUILTIN; // Built-in LED (GPIO 25)
5+
const int LED_WARNING = 15; // External LED on GPIO 15
6+
7+
// --- Callbacks ---
8+
9+
void toggleStatus() {
10+
digitalWrite(LED_STATUS, !digitalRead(LED_STATUS));
11+
}
12+
13+
void toggleWarning() {
14+
digitalWrite(LED_WARNING, !digitalRead(LED_WARNING));
15+
}
16+
17+
void warningFinished() {
18+
digitalWrite(LED_WARNING, LOW); // Ensure LED is off after burst
19+
Serial.println("Warning sequence complete.");
20+
}
21+
22+
// --- Timer Instances ---
23+
24+
// Status LED: Blinks infinitely every 500ms
25+
MillisTimer statusTimer(500, toggleStatus, 0);
26+
27+
// Warning LED: Flashes fast (100ms) for 10 cycles (5 full blinks)
28+
MillisTimer warningTimer(100, toggleWarning, 10);
29+
30+
// A one-shot timer to trigger the warning every 10 seconds
31+
MillisTimer faultSimulator(10000, [](){
32+
Serial.println("Simulating a system fault!");
33+
warningTimer.reset();
34+
}, 0);
35+
36+
void setup() {
37+
Serial.begin(115200);
38+
39+
pinMode(LED_STATUS, OUTPUT);
40+
pinMode(LED_WARNING, OUTPUT);
41+
42+
Serial.println("Multi-LED Controller Active");
43+
}
44+
45+
void loop() {
46+
statusTimer.update();
47+
warningTimer.update();
48+
faultSimulator.update();
49+
50+
// You can also change the speed of the status LED on the fly
51+
if (Serial.available()) {
52+
char c = Serial.read();
53+
if (c == '+') {
54+
statusTimer.setPeriod(100); // Speed up status LED
55+
Serial.println("Status speed: FAST");
56+
} else if (c == '-') {
57+
statusTimer.setPeriod(500); // Slow down status LED
58+
Serial.println("Status speed: SLOW");
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)