Skip to content

Commit

Permalink
Added Chrono::Duration examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lunOptics committed Oct 14, 2020
1 parent 36f7fcd commit 432342b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/01_Basic/UsingChronoDurations1/UsingChronoDurations1.ino
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 examples/01_Basic/UsingChronoDurations2/UsingChronoDurations2.ino
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()
{
}

0 comments on commit 432342b

Please sign in to comment.