ptScheduler - Library Documentation
ptScheduler is a non-preemptive task scheduler for Arduino supported microcontrollers that helps you to write non-blocking periodic tasks easily without using an RTOS.
Last updated
ptScheduler is a non-preemptive task scheduler for Arduino supported microcontrollers that helps you to write non-blocking periodic tasks easily without using an RTOS.
Last updated
This is the documentation for ptScheduler version 1.1.2. If you are using a different version, choose the version from left pane.
Pretty tiny Scheduler or ptScheduler is a non-preemptive task scheduler library for Arduino that helps you to write non-blocking, periodic tasks easily and effectively without using ordinary delay routines or using millis()
function on your own.
Under the hood, ptScheduler uses the native millis()
implementation of Arduino. The millis()
function is a hardware timer based ISR that increments a global counter variable (unsigned integer) every millisecond.
When you create a new ptScheduler object, you can specify the time intervals and execution modes. All the class member variables and functions are public and therefore gives you full control over your tasks, allowing dynamically changing the behavior of the task.
To run a task, just enclose the call()
function inside any conditional statements, either inside your infinite loop or inside a function. Every time you invoke the call()
function, it checks if the elapsed time is larger than the preset interval. If yes, it will return true
and cause the code under the conditional block to be executed once.
ptScheduler is good mainly for control applications that require periodic polling of sensors, GPIOs and other IO devices. ptScheduler tasks can coexist with preemptive tasks such as FreeRTOS tasks.
ptScheduler is an open source library developed by Vishnu Mohanan.
Here's a Hello World example. sayHello
is a ptScheduler task initialized with 1000 millisecond time period. The corresponding call()
function for sayHello
is enclosed inside an if statement. The clause will be executed every 1 second, printing "Hello World" to the serial monitor. You can change this time period dynamically, or get the number of times the clause was executed.
Here is a blink example. The blinkLed
task is set to run every 500 milliseconds. The associated if clause will toggle the LED state every 500 milliseconds. Notice that the new task does interfere with timing of the sayHello
task. Both tasks run only at their specific periods. On line 23
is a statement that will be executed continuously.
A complete tutorial on ptScheduler is available at CIRCUITSTATE.