Tasker: an example that runs
Yes. You can use the Tasker library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (LED). The example below, "Blink on an interval, three beeps on setRepeated, one timeout", runs on the Arduino Uno R3.
Built in on Mokxi: #include <Tasker.h> and it builds, with nothing to install. Free, and no account needed.
What Tasker does
SetTimeout(), setInterval() and setRepeated(n) for plain functions (with an optional int), run from tasker.loop(); cancel(), isScheduled(), scheduledIn(). That is what Tasker, by Petr Stehlik, covers. The sketch below uses it on the Arduino Uno: “Blink on an interval, three beeps on setRepeated, one timeout”.
Petr Stehlik's Tasker library (3.0.0), JavaScript-style setTimeout(), setInterval() and setRepeated() run from loop().
A function may take an int, given after the time: setInterval(f, 500, 3). setRepeated(f, ms, n) runs it n times. cancel() (or clearTimeout(), clearInterval()) takes the function (and int) back; isScheduled() and scheduledIn() ask about it.
The calls follow release 3.0.0 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.
| Library Manager name | Tasker |
|---|---|
| Author | Petr Stehlik |
| Include | #include <Tasker.h> |
| Boards | every board Mokxi compiles for |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | LED |
Install it
It builds on every board Mokxi compiles for.
In Mokxi it is built in: #include <Tasker.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "Tasker" by Petr Stehlik from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Tasker to lib_deps in PlatformIO. Mokxi follows the calls of release 3.0.0, so a sketch written here builds there too.
- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- ATtiny85
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
Tasker tasker
Makes tasker, the Tasker object the calls below are made on.
tasker.isScheduled(blink)
Returns true or false for "is scheduled".
tasker.setInterval(blink, 100)
Sets the interval to the value you pass in.
tasker.setRepeated(beep, 200, 3, 1)
Sets the repeated to the value you pass in.
tasker.setTimeout(later, 1000)
Sets the timeout to the value you pass in.
Example: Blink on an interval, three beeps on setRepeated, one timeout
On the Arduino Uno R3. It runs in the browser exactly as printed.
// After the library's Blink example.
#include <Tasker.h>
Tasker tasker;
int beeps = 0;
void blink() {
digitalWrite(13, !digitalRead(13));
}
void beep(int n) {
beeps += n;
Serial.print("beep ");
Serial.println(beeps);
}
void later() {
tasker.cancel(blink);
Serial.print("blink scheduled: ");
Serial.println(tasker.isScheduled(blink) ? "yes" : "no");
}
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
tasker.setInterval(blink, 100);
tasker.setRepeated(beep, 200, 3, 1);
tasker.setTimeout(later, 1000);
}
void loop() {
tasker.loop();
}Wiring
- Arduino Uno R3 13 to LED A
- Arduino Uno R3 GND to LED C
Keep going
Try Tasker without installing anything
Open the example, change the sketch, and keep your version in a free account.