Please include <Ticker.h> before using
Description:
Executes the callback function only once at a set time point (in seconds).
Syntax:
void once(float seconds, callback_t callback);
Parameter | Type | Description |
---|---|---|
seconds | float | Time in seconds to execute |
callback | callback_t | Callback function |
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 objectvoid 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);}
Description:
Calls the callback function only once after a set time (in milliseconds).
Syntax:
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 |
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 objectvoid 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);}
Description:
Executes the callback function periodically every set interval (in seconds).
Syntax:
void attach(float seconds, callback_t callback);
Parameter | Type | Description |
---|---|---|
seconds | float | Interval in seconds |
callback | callback_t | Callback function name |
Example:
#include <M5Stack.h>#include <Ticker.h> Ticker ticker; // Create a Ticker for implementing timing functionalityint count; // Variable for counting // This function will be executed periodically under the control of the Tinker objectvoid 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);}
Description:
Executes the callback function periodically every set interval (in milliseconds).
Syntax:
void attach_ms(uint32_t milliseconds, callback_t callback);
Parameter | Type | Description |
---|---|---|
milliseconds | uint32_t | Interval in milliseconds |
callback | callback_t | Callback function name |
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() {}
Description:
Executes the callback function with parameters periodically every set interval (in seconds).
Syntax:
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 |
Example:
#include <M5Stack.h>#include <Ticker.h> Ticker tickerSetHigh; // Create a Ticker for implementing timing functionalityTicker 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() {}
Description:
Executes the callback function with parameters periodically every set interval (in milliseconds).
Syntax:
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 |
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() {}