Skip to content

An Arduino library for creating Tickers, which will notify user that a given period has elapsed.

License

Notifications You must be signed in to change notification settings

JSC-TechMinds/Ticker

Repository files navigation

Ticker

PlatformIO Documentation License: Apache 2.0 GitHub release JSC TechMinds Donate

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();
    }
}

Documentation

Contributing

There are many ways in which you can participate in the project, for example:

Please read contributing rules for more details.

License

Copyright © 2020-2024 JSC TechMinds. All rights reserved.

Licensed under the Apache-2.0 license.

Support

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.

paypal