Skip to content

esp32 library that calls functions periodically (similar to "Ticker.h" for esp8266)

License

Notifications You must be signed in to change notification settings

sglvladi/Ticker_ESP32

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ticker_ESP32

A primitive library which makes use of the hardware timers in ESP32, to provide similar funtionality and interface akin to the "Ticker.h" library for ESP8266.

Differences to "Ticker.h" for ESP8266

  • Each Ticker instance must be provided with the id of the respective hw timer which should be employed. Valid ids can be in the range 0-3. (e.g. Ticker LED_Ticker_1(2);)
  • ESP32 has 4 hw timers, which means up to 4 Ticker instances can be instantiated, one for each timer.
  • Unlike "Ticker.h", callback functions with arguments are not supported (yet).

Usage

  • Define a Ticker instance (e.g. on 4th hw timer):
Ticker myTicker(3);
  • Define a callback function to be called when timer fires:
void myCallback(){
  // Do something interesting...
}
  • Initiate the timer and attach our callback to be run at a certain interval (e.g. 1 sec):
myTicker.attach(1, myCallback); 

or

myTicker.attach_us(1000000, myCallback); // 1 second = 1000000 microseconds
  • When desired, stop the timer and detach the callback:
myTicker.detach();

See the blinkLEDs sketch, for a full example.

About

esp32 library that calls functions periodically (similar to "Ticker.h" for esp8266)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages