-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
examples/01_Basic/UsingChronoDurations1/UsingChronoDurations1.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "TeensyTimerTool.h" | ||
using namespace TeensyTimerTool; | ||
|
||
PeriodicTimer t1(TCK); | ||
PeriodicTimer t2(TCK); | ||
|
||
void isr1() | ||
{ | ||
Serial.printf("called @: %u ms\n", millis()); | ||
} | ||
|
||
void isr2() | ||
{ | ||
digitalToggleFast(LED_BUILTIN); | ||
} | ||
|
||
void setup() | ||
{ | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
|
||
t1.begin(isr1, 5.02s); // instead of 5020000 | ||
t2.begin(isr2, 25ms); // instead of 25000 | ||
} | ||
|
||
void loop() | ||
{ | ||
} |
30 changes: 30 additions & 0 deletions
30
examples/01_Basic/UsingChronoDurations2/UsingChronoDurations2.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "TeensyTimerTool.h" | ||
using namespace TeensyTimerTool; | ||
|
||
OneShotTimer timer[]{TCK, TCK, TCK, TCK}; // 5 one-shot-timers | ||
unsigned t_0; // start time | ||
|
||
void isr() | ||
{ | ||
Serial.printf("called @: %u ms\n", millis() - t_0); | ||
} | ||
|
||
void setup() | ||
{ | ||
while (!Serial) {} // wait for PC to connect the virtual serial port | ||
|
||
for (OneShotTimer& t : timer) // for the sake of simplicity, attach the same isr to all timers in array | ||
{ | ||
t.begin(isr); | ||
} | ||
|
||
timer[0].trigger(10ms); // 10 ms | ||
timer[1].trigger(0.5s + 10ms); // 510 ms | ||
timer[2].trigger(2.5 * 0.3s + 20'000us / 2); // 760 ms | ||
timer[3].trigger(milliseconds(50) + microseconds(5000)); // 55ms | ||
t_0 = millis(); | ||
} | ||
|
||
void loop() | ||
{ | ||
} |