Skip to content

Commit 69b5486

Browse files
authored
Add SerialDemo.ino in a modified directory structure.
1 parent 5d5ff36 commit 69b5486

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

examples/SerialDemo/SerialDemo.ino

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <PicoTimer.h>
2+
3+
// --- Callbacks ---
4+
5+
void alarmCallback() {
6+
Serial.println("--- ALARM: One-shot triggered! I am now stopped. ---");
7+
}
8+
9+
void heartbeatCallback() {
10+
static uint32_t count = 0;
11+
Serial.print("HEARTBEAT: ");
12+
Serial.println(++count);
13+
}
14+
15+
void burstCallback() {
16+
static uint32_t pulses = 0;
17+
Serial.print("BURST: Pulse ");
18+
Serial.println(++pulses);
19+
}
20+
21+
// --- Timer Instances ---
22+
23+
// 1. One-shot: Runs once after 5 seconds (5000ms)
24+
MillisTimer alarm(5000, alarmCallback, 1);
25+
26+
// 2. Infinite: Runs every 1 second (1,000,000 microseconds)
27+
MicrosTimer heartbeat(1000000, heartbeatCallback, 0);
28+
29+
// 3. Finite: Runs exactly 10 times, every 200ms
30+
MillisTimer burst(200, burstCallback, 10);
31+
32+
void setup() {
33+
Serial.begin(115200);
34+
while (!Serial) delay(10); // Wait for Serial on Pico
35+
36+
Serial.println("PicoTimer Serial Demo Started");
37+
Serial.println("-----------------------------");
38+
}
39+
40+
void loop() {
41+
// Always call update() in the loop for every timer
42+
alarm.update();
43+
heartbeat.update();
44+
burst.update();
45+
46+
// Logic to restart the burst if it finishes
47+
if (!burst.isRunning()) {
48+
delay(2000);
49+
Serial.println("Restarting burst timer...");
50+
burst.reset();
51+
}
52+
}

0 commit comments

Comments
 (0)