Class EpdIF
GTimerClass Class
Members
Public Constructors |
|
---|---|
GTimerClass::GTimerClass |
Constructs a GTimerClass object |
Public Methods |
|
GTimerClass::begin |
Initialize a timer and start it immediately |
GTimerClass::stop |
Stop a specific timer |
GTimerClass::reload |
Reload a specific timer |
GTimerClass::read_us |
Read current countdown value |
GTimerClass::begin
/*
This sketch shows how to use several hardware timers in invoke handler only once for each timer.
*/
#include <GTimer.h>
void myhandler(uint32_t data) {
Serial.print(“I am timer!”);
Serial.println(data);
}
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// timerid 0, period 1s, invoke myhandler, invoke only once, user data is 0
GTimer.begin(0, 1 * 1000 * 1000, myhandler, false, 0);
// timerid 1, period 2s, invoke myhandler, invoke only once, user data is 1
GTimer.begin(1, 2 * 1000 * 1000, myhandler, false, 1);
GTimer.begin(2, 3 * 1000 * 1000, myhandler, false, 2);
GTimer.begin(3, 4 * 1000 * 1000, myhandler, false, 3);
}
void loop() {
delay(1000);
}
Example: TimerPeriodical
/*
This sketch shows how to use hardware timer and invoke interrupt handler periodically
*/
#include <GTimer.h>
int counter = 0;
void myhandler(uint32_t data) {
counter++;
Serial.print(“counter: “);
Serial.println(counter);
if (counter >= 10) {
Serial.println(“stop timer”);
GTimer.stop(0);
}
}
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// timerid 0, period 1s, invoke myhander
GTimer.begin(0, (1 * 1000 * 1000), myhandler);
}
void loop() {
delay(1000);
}
GTimerClass::stop
GTimerClass::reload
GTimerClass::read_us