Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luni64/intervaltimerex
https://github.com/luni64/intervaltimerex
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/luni64/intervaltimerex
- Owner: luni64
- License: mit
- Created: 2022-09-03T06:06:03.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-22T12:09:48.000Z (12 months ago)
- Last Synced: 2023-11-22T13:31:40.781Z (12 months ago)
- Language: C++
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# IntervalTimerEx
IntervalTimerEx is a lightweight extension of the stock Teensyduino IntervalTimer.
It extends the standard Teensy IntervalTimer to accept more or less anything which can be called as callback. E.g. free functions, static member functions, lambda expressions (capturing and non-capturing) and functors. IntervalTimerEx uses the underlying Teensyduino mechanisms and bookkeeping and can be mixed with the standard IntervalTimer.Installation through the Arduino Library Manager or the PIO registry.
### Example:
```c++
#include "Arduino.h"
#include "IntervalTimerEx.h"// Free function callback ------------------------------------------------------
void freeFunction()
{
Serial.println("Free function callback");
}// Using a non static member function as callback -------------------------------
class Test
{
public:
Test(int _i){
i = _i;
}void someMemberFunction(float f){
Serial.printf("non static member function i=%f\n", i * f);
}int i;
};
Test test(42);//------------------------------------------------------
class MyFunctor_t
{
public:
void set(int _i){
i = _i;
}void operator()() const {
Serial.printf("Functor i=%d\n", i);
}protected:
int i = 2;
};
MyFunctor_t functor;//------------------------------------------------------
IntervalTimerEx t1, t2, t3, t4;
void setup()
{
// generate various callbacks
t1.begin(freeFunction, 250'000); // free function
t2.begin(functor, 250'000); // functor
t3.begin([] { Serial.printf("non capturing lambda\n"); }, 250'000); // simple, non capturing lambda
t4.begin([] { test.someMemberFunction(3.1415); }, 250'000); // non static member function
}elapsedMillis stopwatch = 0;
void loop()
{
// change state of functor and test class on the fly
if (stopwatch > 1000)
{
functor.set(random(0, 1000));
test.i = random(0, 10000);
stopwatch = 0;
}
}
```