Ticker is a helper library, which allows you to write non-blocking Arduino code without calls to delay()
.
There are two common ways, how to use the library. Let's say you want to trigger an event after five seconds:
#include <Ticker.h>
#define TRIGGER_PERIOD 5000 // milliseconds
// Create a ticker
jsc::Ticker ticker(TRIGGER_PERIOD);
void setup() {
...
}
void loop() {
if (ticker.elapsedTicks() > 0) {
// TODO: Trigger an event
// Reset ticker
ticker.restart();
}
}
In another example, we want to trigger an event after five seconds, as in first case. However, Ticker will increment its counter after 10 milliseconds, which is a default value. To determine, whether a time period has elapsed, you need to divide overall time period by partial time periods. This value represents expected counter value. Let's see an example:
#include <Ticker.h>
// Create a ticker with a tick period of 10 ms
jsc::Ticker ticker();
void setup() {
...
}
void loop() {
// Trigger an event after five seconds
if (ticker.elapsedTicks() > (5000 / 10)) {
// TODO: Trigger an event
// Reset ticker
ticker.restart();
}
}
There are many ways in which you can participate in the project, for example:
- Submit bugs and feature requests, and help us verify as they are checked in
- Review source code changes
- Review the documentation and make pull requests for anything from typos to new content
Please read contributing rules for more details.
Copyright © 2020-2024 JSC TechMinds. All rights reserved.
Licensed under the Apache-2.0 license.
We hope our library helped to speed up your project development. You can support our effort to convert coffe and pizza into a code with a small donation. Any support is much appreciated.