https://github.com/esptoolkit/esp-timer
Async timer helpers mirroring setTimeout / setInterval with dedicated countdown utilities for seconds, minutes and milliseconds.
https://github.com/esptoolkit/esp-timer
arduino async embedded esp32 freertos software-timer timer
Last synced: 5 months ago
JSON representation
Async timer helpers mirroring setTimeout / setInterval with dedicated countdown utilities for seconds, minutes and milliseconds.
- Host: GitHub
- URL: https://github.com/esptoolkit/esp-timer
- Owner: ESPToolKit
- License: mit
- Created: 2025-09-16T07:59:01.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-09-25T09:46:14.000Z (6 months ago)
- Last Synced: 2025-09-25T11:36:11.387Z (6 months ago)
- Topics: arduino, async, embedded, esp32, freertos, software-timer, timer
- Language: C++
- Homepage: https://esptoolkitfrontend.onrender.com/
- Size: 30.3 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Roadmap: ROADMAP.md
Awesome Lists containing this project
README
# ESPTimer
[](https://github.com/ESPToolKit/esp-timer/actions/workflows/ci.yml)
[](https://github.com/ESPToolKit/esp-timer/releases)
[](LICENSE.md)
Lightweight JS-like timers for ESP32 with non-blocking FreeRTOS tasks.
Features
- `setTimeout` (one-shot), `setInterval` (periodic)
- Counters: per-second, per-millisecond, per-minute with remaining time
- Each timer type runs on its own FreeRTOS task
- Pause, resume, toggle run status, clear, and status query per timer ID
Quick Start
- Include `#include ` and call `timer.init()` once (optionally with `ESPTimerConfig`).
- Use the API similar to JS timers:
```cpp
// Triggers once
uint32_t id1 = timer.setTimeout([](){
Serial.println("1.5 sec is timed out!");
}, 1500);
// Retriggers every 1500ms
uint32_t id2 = timer.setInterval([](){
Serial.println("1.5 sec is triggered!");
}, 1500);
// Called every sec for 10000 ms
uint32_t id3 = timer.setSecCounter([](int secLeft){
Serial.printf("%d sec left so far\n", secLeft);
}, 10000);
// Called every ms for 10000 ms
uint32_t id4 = timer.setMsCounter([](uint32_t msLeft){
// msLeft can be high frequency; keep work light
}, 10000);
// Called every min for 10000 ms
uint32_t id5 = timer.setMinCounter([](int minLeft){
Serial.printf("%d min left so far\n", minLeft);
}, 10000);
// Pause, resume, toggle, and clear
timer.pauseInterval(id2); // Pauses if running
timer.resumeInterval(id2); // Resumes if paused
bool running = timer.toggleRunStatusInterval(id2); // Toggles; true if now running
timer.clearInterval(id2);
// Status
ESPTimerStatus status = timer.getStatus(id1);
```
Notes
- `pause*` only pauses (idempotent). Use `resume*` to resume, or `toggleRunStatus*` to toggle (returns `true` if now running).
- `setMsCounter` can be CPU intensive; use sparingly and keep callbacks very light.
- Each type uses its own FreeRTOS task. Configure stack, priority, and core with `ESPTimerConfig`.
See `examples/Basic/Basic.ino` for a complete sketch.
## ESPToolKit
- Check out other libraries under ESPToolKit: https://github.com/orgs/ESPToolKit/repositories
- Join our discord server at: https://discord.gg/WG8sSqAy
- If you like the libraries, you can support me at: https://ko-fi.com/esptoolkit