Please include <Ticker.h> before using
Functionality:
Executes the callback function only once at a set time point (in seconds).
Function Prototype:
void once(float seconds, callback_t callback)
Parameter | Type | Description |
---|---|---|
seconds | float | Time in seconds to execute |
callback | callback_t | Callback function |
Usage Example:
#include <M5Stack.h>
#include <Ticker.h>
Ticker ticker; // Create a Ticker for implementing timing functionality
// This function will be executed periodically under the control of the Tinker object
void sayHi() {
Serial.print("Hi,Ticker!");
}
void setup() {
M5.begin();
// Call the sayHi function once after 3 seconds
ticker.once(3, sayHi);
}
void loop() {
// M5Stack can perform other tasks periodically under the control of Tinker object
Serial.println("Ticker");
delay(1000);
}
Functionality:
Calls the callback function only once after a set time (in milliseconds).
Function Prototype:
void once_ms(uint32_t milliseconds, callback_t callback)
Parameter | Type | Description |
---|---|---|
milliseconds | uint32_t | Time in milliseconds to execute |
callback | callback_t | Callback function |
Usage Example:
#include <M5Stack.h>
#include <Ticker.h>
Ticker ticker; // Create a Ticker for implementing timing functionality
// This function will be executed periodically under the control of the Tinker object
void sayHi() {
Serial.println("Hi,Ticker!");
}
void setup() {
M5.begin();
// Call the sayHi function once at 3000 milliseconds
ticker.once_ms(3000, sayHi);
}
void loop() {
// M5Stack can perform other tasks periodically under the control of Tinker object
Serial.println("Ticker");
delay(1000);
}
Functionality:
Executes the callback function periodically every set interval (in seconds).
Function Prototype:
void attach(float seconds, callback_t callback)
Parameter | Type | Description |
---|---|---|
seconds | float | Interval in seconds |
callback | callback_t | Callback function name |
Usage Example:
#include <M5Stack.h>
#include <Ticker.h>
Ticker ticker; // Create a Ticker for implementing timing functionality
int count; // Variable for counting
// This function will be executed periodically under the control of the Tinker object
void sayHi() {
count++;
Serial.print("Hi ");
Serial.println(count);
}
void setup() {
M5.begin();
// Call the sayHi function every one second
ticker.attach(1, sayHi);
}
void loop() {
// M5Stack can perform other tasks periodically under the control of Tinker object
Serial.println("Ticker");
delay(3000);
}
Functionality:
Executes the callback function periodically every set interval (in milliseconds).
Function Prototype:
void attach_ms(uint32_t milliseconds, callback_t callback)
Parameter | Type | Description |
---|---|---|
milliseconds | uint32_t | Interval in milliseconds |
callback | callback_t | Callback function name |
Usage Example:
#include <M5Stack.h>
#include <Ticker.h>
Ticker tickerSetHigh;
Ticker tickerSetLow;
void display(int number) {
M5.Lcd.setCursor(0, 0);
M5.Lcd.print(number);
}
void setup() {
M5.begin();
tickerSetLow.attach_ms(1000, display, 0); // Execute a callback function with parameters every 1 second
tickerSetHigh.attach_ms(2000, display, 1);
}
void loop() {
}
Functionality:
Executes the callback function with parameters periodically every set interval (in seconds).
Function Prototype:
void attach(float seconds, void (*callback)(TArg), TArg arg)
Parameter | Type | Description |
---|---|---|
seconds | float | Interval in seconds |
callback | callback_t | Callback function with parameters |
arg | TArg | Function parameter |
Usage Example:
#include <M5Stack.h>
#include <Ticker.h>
Ticker tickerSetHigh; // Create a Ticker for implementing timing functionality
Ticker tickerSetLow;
void display(int number) {
M5.Lcd.setCursor(0,
0);
M5.Lcd.print(number);
}
void setup() {
M5.begin();
tickerSetLow.attach(1, display, 0); // Execute a callback function with parameters every 1 second
tickerSetHigh.attach(2, display, 1);
}
void loop() {}
Functionality:
Executes the callback function with parameters periodically every set interval (in milliseconds).
Function Prototype:
void attach_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg)
Parameter | Type | Description |
---|---|---|
milliseconds | uint32_t | Interval in milliseconds |
callback | callback_t | Callback function with parameters |
arg | TArg | Function parameter |
Usage Example:
#include <M5Stack.h>
#include <Ticker.h>
Ticker tickerSetHigh;
Ticker tickerSetLow;
void display(int number) {
M5.Lcd.setCursor(0, 0);
M5.Lcd.print(number);
}
void setup() {
M5.begin();
tickerSetLow.attach_ms(1000, display, 0);
tickerSetHigh.attach_ms(2000, display, 1);
}
void loop() {}