├── .gitignore ├── examples ├── .DS_Store ├── Ticker │ └── Ticker.ino └── FunctionalARM │ └── FunctionalARM.ino ├── keywords.txt ├── library.json ├── library.properties ├── LICENSE ├── TickTwo.cpp ├── TickTwo.h └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /examples/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sstaub/TickTwo/HEAD/examples/.DS_Store -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | TickTwo KEYWORD1 2 | start KEYWORD2 3 | resume KEYWORD2 4 | pause KEYWORD2 5 | stop KEYWORD2 6 | update KEYWORD2 7 | interval KEYWORD2 8 | state KEYWORD2 9 | counter KEYWORD2 10 | elapsed KEYWORD2 11 | remaining KEYWORD2 12 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TickTwo", 3 | "keywords": "Ticker, Timer, Threads", 4 | "description": "A library for creating Tickers which can call repeating functions. Replaces delay() with non-blocking functions. Recommended for ESP and Arduino boards with mbed behind.", 5 | "repository": 6 | { 7 | "type": "git", 8 | "url": "https://github.com/sstaub/TickTwo" 9 | }, 10 | "version": "4.4.0", 11 | "frameworks": "arduino", 12 | "platforms": "*" 13 | } 14 | 15 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=TickTwo 2 | version=4.4.0 3 | author=Stefan Staub 4 | maintainer=Stefan Staub 5 | sentence=A library for creating Tickers which can call repeating functions. Replaces delay() with non-blocking functions. Recommended for ESP and Arduino boards with mbed behind. 6 | paragraph=The Arduino Ticker Library allows you to create easily Ticker callbacks, which can call a function in a predetermined interval. You can change the number of repeats of the callbacks, if repeats is 0 the ticker runs in endless mode. Works like a "thread", where a secondary function will run when necessary. The library use no interupts of the hardware timers and works with the micros() / millis() function. You are not (really) limited in the number of Tickers. 7 | category=Timing 8 | url=https://github.com/sstaub/TickTwo 9 | architectures=* 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Stefan Staub 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/Ticker/Ticker.ino: -------------------------------------------------------------------------------- 1 | #include "TickTwo.h" 2 | 3 | void printMessage(); 4 | void printCounter(); 5 | void printCountdown(); 6 | void blink(); 7 | void printCountUS(); 8 | 9 | bool ledState; 10 | int counterUS; 11 | 12 | TickTwo timer1(printMessage, 0, 1); 13 | TickTwo timer2(printCounter, 1000, 0, MILLIS); 14 | TickTwo timer3(printCountdown, 1000, 5); 15 | TickTwo timer4(blink, 500); 16 | TickTwo timer5(printCountUS, 100, 0, MICROS_MICROS); 17 | 18 | 19 | void setup() { 20 | pinMode(LED_BUILTIN, OUTPUT); 21 | Serial.begin(9600); 22 | delay(2000); 23 | timer1.start(); 24 | timer2.start(); 25 | timer3.start(); 26 | timer4.start(); 27 | timer5.start(); 28 | } 29 | 30 | void loop() { 31 | timer1.update(); 32 | timer2.update(); 33 | timer3.update(); 34 | timer4.update(); 35 | timer5.update(); 36 | if (timer4.counter() == 20) timer4.interval(200); 37 | if (timer4.counter() == 80) timer4.interval(1000); 38 | } 39 | 40 | void printCounter() { 41 | Serial.print("Counter "); 42 | Serial.println(timer2.counter()); 43 | } 44 | 45 | void printCountdown() { 46 | Serial.print("Countdowm "); 47 | Serial.println(5 - timer3.counter()); 48 | } 49 | 50 | void printMessage() { 51 | Serial.println("Hello!"); 52 | } 53 | 54 | void blink() { 55 | digitalWrite(LED_BUILTIN, ledState); 56 | ledState = !ledState; 57 | } 58 | 59 | void printCountUS() { 60 | counterUS++; 61 | if (counterUS == 10000) { 62 | Serial.println("10000 * 100us"); 63 | counterUS = 0; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /examples/FunctionalARM/FunctionalARM.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void func() { 4 | Serial.println("func."); 5 | } 6 | 7 | TickTwo ticker1(func, 1000, 0, MILLIS); 8 | 9 | // Simple class with (non static) method 10 | class A { 11 | public: 12 | A(bool flag) : flag(flag) {} 13 | 14 | void func() { 15 | Serial.printf("A::func: %s.\n", flag ? "true" : "false"); 16 | } 17 | bool flag; 18 | }; 19 | 20 | A a1(true); 21 | 22 | // use lambda to capture a1 and execute a1.func() 23 | 24 | TickTwo ticker2([](){a1.func();}, 1000, 0, MILLIS); 25 | 26 | A a2(false); 27 | 28 | TickTwo ticker3([](){a2.func();}, 1000, 0, MILLIS); 29 | 30 | // Class that registers its own method as a callback when it's instantiated. 31 | class B { 32 | public: 33 | B(bool flag) : flag(flag), ticker{[this](){this->func();}, 1000, 0, MILLIS} { 34 | ticker.start(); 35 | } 36 | 37 | void func() { 38 | Serial.printf("B::func: %s.\n", flag ? "true" : "false"); 39 | } 40 | bool flag; 41 | Ticker ticker; 42 | }; 43 | 44 | B b(true); 45 | 46 | // Class that acts like a function (functor) 47 | class C { 48 | public: 49 | C(int num) : num(num){} 50 | 51 | // you can call an instance directly with parenthesis and this is executed 52 | void operator()() const { 53 | Serial.printf("C(): %d.\n", num); 54 | } 55 | int num; 56 | }; 57 | 58 | C c(4); 59 | 60 | TickTwo ticker4(c, 1000, 0, MILLIS); 61 | 62 | void setup() { 63 | Serial.begin(115200); 64 | delay(1000); 65 | Serial.println(); 66 | 67 | ticker1.start(); 68 | ticker2.start(); 69 | ticker3.start(); 70 | ticker4.start(); 71 | } 72 | 73 | void loop() { 74 | ticker1.update(); 75 | ticker2.update(); 76 | ticker3.update(); 77 | b.ticker.update(); 78 | ticker4.update(); 79 | } 80 | -------------------------------------------------------------------------------- /TickTwo.cpp: -------------------------------------------------------------------------------- 1 | /* Ticker library code is placed under the MIT license 2 | * Copyright (c) 2018 Stefan Staub 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "TickTwo.h" 26 | 27 | TickTwo::TickTwo(fptr callback, uint32_t timer, uint32_t repeat, resolution_t resolution) { 28 | this->resolution = resolution; 29 | if (resolution == MICROS) timer = timer * 1000; 30 | this->timer = timer; 31 | this->repeat = repeat; 32 | this->callback = callback; 33 | enabled = false; 34 | lastTime = 0; 35 | counts = 0; 36 | } 37 | 38 | TickTwo::~TickTwo() {} 39 | 40 | void TickTwo::start() { 41 | if (callback == NULL) return; 42 | if (resolution == MILLIS) lastTime = millis(); 43 | else lastTime = micros(); 44 | enabled = true; 45 | counts = 0; 46 | status = RUNNING; 47 | } 48 | 49 | void TickTwo::resume() { 50 | if (callback == NULL) return; 51 | if (resolution == MILLIS) lastTime = millis() - diffTime; 52 | else lastTime = micros() - diffTime; 53 | if (status == STOPPED) counts = 0; 54 | enabled = true; 55 | status = RUNNING; 56 | } 57 | 58 | void TickTwo::stop() { 59 | enabled = false; 60 | counts = 0; 61 | status = STOPPED; 62 | } 63 | 64 | void TickTwo::pause() { 65 | if (resolution == MILLIS) diffTime = millis() - lastTime; 66 | else diffTime = micros() - lastTime; 67 | enabled = false; 68 | status = PAUSED; 69 | } 70 | 71 | void TickTwo::update() { 72 | if (tick()) callback(); 73 | } 74 | 75 | bool TickTwo::tick() { 76 | if (!enabled) return false; 77 | uint32_t currentTime = (resolution == MILLIS) ? millis() : micros(); 78 | if ((currentTime - lastTime) >= timer) { 79 | lastTime = currentTime; 80 | if (repeat - counts == 1 && counts != 0xFFFFFFFF) { 81 | enabled = false; 82 | status = STOPPED; 83 | } 84 | counts++; 85 | return true; 86 | } 87 | return false; 88 | } 89 | 90 | void TickTwo::interval(uint32_t timer) { 91 | if (resolution == MICROS) timer *= 1000; 92 | this->timer = timer; 93 | } 94 | 95 | uint32_t TickTwo::interval() { 96 | if (resolution == MILLIS) return timer / 1000; 97 | else return timer; 98 | } 99 | 100 | uint32_t TickTwo::elapsed() { 101 | if (resolution == MILLIS) return millis() - lastTime; 102 | else return micros() - lastTime; 103 | } 104 | 105 | uint32_t TickTwo::remaining() { 106 | return timer - elapsed(); 107 | } 108 | 109 | status_t TickTwo::state() { 110 | return status; 111 | } 112 | 113 | uint32_t TickTwo::counter() { 114 | return counts; 115 | } 116 | -------------------------------------------------------------------------------- /TickTwo.h: -------------------------------------------------------------------------------- 1 | /* Ticker library code is placed under the MIT license 2 | * Copyright (c) 2018 Stefan Staub 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef TICKTWO_H 26 | #define TICKTWO_H 27 | 28 | #include "Arduino.h" 29 | 30 | /** Ticker internal resolution 31 | * 32 | * @param MICROS default, the resolution is in micro seconds, max is 70 minutes, the real resolution is 4 microseconds at 16MHz CPU cycle 33 | * @param MILLIS set the resolution to millis, for longer cycles over 70 minutes 34 | * 35 | */ 36 | enum resolution_t { 37 | MICROS, 38 | MILLIS, 39 | MICROS_MICROS 40 | }; 41 | 42 | /** Ticker status 43 | * 44 | * @param STOPPED default, ticker is stopped 45 | * @param RUNNING ticker is running 46 | * @param PAUSED ticker is paused 47 | * 48 | */ 49 | enum status_t { 50 | STOPPED, 51 | RUNNING, 52 | PAUSED}; 53 | 54 | #if defined(__arm__) || defined(ESP8266) || defined(ESP32) 55 | #include 56 | using fptr = std::function; 57 | #else 58 | typedef void (*fptr)(); 59 | #endif 60 | 61 | 62 | class TickTwo { 63 | 64 | public: 65 | 66 | /** create a Ticker object 67 | * 68 | * @param callback the name of the function to call 69 | * @param timer interval length in ms or us 70 | * @param repeat default 0 -> endless, repeat > 0 -> number of repeats 71 | * @param resolution default MICROS for tickers under 70min, use MILLIS for tickers over 70 min 72 | * 73 | */ 74 | TickTwo(fptr callback, uint32_t timer, uint32_t repeat = 0, resolution_t resolution = MICROS); 75 | 76 | /** destructor for the Ticker object 77 | * 78 | */ 79 | ~TickTwo(); 80 | 81 | /** start the ticker 82 | * 83 | */ 84 | void start(); 85 | 86 | /** resume the ticker. If not started, it will start it. 87 | * 88 | */ 89 | void resume(); 90 | 91 | /** pause the ticker 92 | * 93 | */ 94 | void pause(); 95 | 96 | /** stops the ticker 97 | * 98 | */ 99 | void stop(); 100 | 101 | /** must to be called in the main loop(), it will check the Ticker, and if necessary, will run the callback 102 | * 103 | */ 104 | void update(); 105 | 106 | /** 107 | * @brief set the interval timer 108 | * 109 | * @param timer interval length in ms or us 110 | */ 111 | void interval(uint32_t timer); 112 | 113 | /** 114 | * @brief get the interval time 115 | * 116 | * @returns the interval time 117 | */ 118 | uint32_t interval(); 119 | 120 | /** actual elapsed time 121 | * 122 | * @returns the elapsed time after the last tick 123 | * 124 | */ 125 | uint32_t elapsed(); 126 | 127 | /** time remaining to the next tick 128 | * 129 | * @returns the remaining time to the next tick in ms or us depending from mode 130 | * 131 | */ 132 | uint32_t remaining(); 133 | 134 | /** get the state of the ticker 135 | * 136 | * @returns the state of the ticker: STOPPED, RUNNING or PAUSED 137 | */ 138 | status_t state(); 139 | 140 | /** get the numbers of executed repeats 141 | * 142 | * @returns the number of executed repeats 143 | * 144 | */ 145 | uint32_t counter(); 146 | 147 | private: 148 | bool tick(); 149 | bool enabled; 150 | uint32_t timer; 151 | uint32_t repeat; 152 | resolution_t resolution = MICROS; 153 | uint32_t counts; 154 | status_t status; 155 | fptr callback; 156 | uint32_t lastTime; 157 | uint32_t diffTime; 158 | }; 159 | 160 | #endif 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arduino TickTwo Library v4.x.x for ESP and mbed based Arduino devices 2 | 3 | **This library is a rebrand of the Ticker library, because of naming conflicts with ESP based microcontrollers which is also a problem with mbed based Arduino devices like Raspberry Pi Pico or Arduino Nano RP2040 connect and Potenta boards** 4 | 5 | The **Arduino TickTwo Library** allows you to create easily Ticker callbacks, which can call a function in a predetermined interval. 6 | You can change the number of repeats of the callbacks, if repeats is 0 the ticker runs in endless mode. Works like a "thread", where a secondary function will run when necessary. The library use no interupts of the hardware timers and works with the **micros() / millis()** function. You are not (really) limited in the number of Tickers. 7 | 8 | ## New in v4.0 9 | - added get interval function 10 | - added remaining function 11 | - added support for functional callbacks, only for ARM and ESP devices, e.g.
"Examples/FunctionalARM/FunctionalARM.ino" 12 | 13 | ## New in v3.1 14 | - added set interval function 15 | 16 | ## New in v3.0 17 | - radical simplified API 18 | - generally you have to declare all settings in the constructor 19 | - deleted many set and get functions 20 | - if you need former functionality please use the version 2.1 21 | 22 | ## New in v2.1 23 | - You can change the interval time to microseconds. 24 | ```cpp 25 | TickTwo tickerObject(callbackFunction, 100, 0, MICROS_MICROS) // interval is now 100us 26 | ``` 27 | - smaller improvements 28 | 29 | ## New in v2.0 30 | - You can determine the number of repeats, instead of modes. 31 | - The internal resolution is now **micros()**, this works with intervals up to 70 minutes. For longer intervals you can change the resolution to **millis()**. 32 | ```cpp 33 | TickTwo tickerObject(callbackFunction, 1000, 0, MILLIS) 34 | ``` 35 | - unified data types and smaller improvements 36 | 37 | ## Installation 38 | 39 | 1. "Download":https://github.com/sstaub/TickTwo/archive/master.zip the Master branch from GitHub. 40 | 2. Unzip and modify the folder name to "TickTwo" 41 | 3. Move the modified folder on your Library folder (On your `Libraries` folder inside Sketchbooks or Arduino software). 42 | 43 | 44 | ## How to use 45 | 46 | First, include the TimerObject to your project: 47 | 48 | ```cpp 49 | #include "TickTwo.h" 50 | ``` 51 | 52 | Now, you can create a new object in setup(): 53 | 54 | ```cpp 55 | TickTwo tickerObject(callbackFunction, 1000); 56 | tickerObject.start(); //start the ticker. 57 | ``` 58 | 59 | In your loop(), add: 60 | 61 | ```cpp 62 | tickerObject.update(); //it will check the Ticker and if necessary, it will run the callback function. 63 | ``` 64 | 65 | 66 | ## IMPORTANT 67 | If you use delay(), the Ticker will be ignored! You cannot use delay() command with the TimerObject. Instead of using delay, you can use the Ticker itself. For example, if you need that your loop run twice per second, just create a Ticker with 500 ms. It will have the same result that delay(500), but your code will be always state. 68 | 69 | ## Example 70 | 71 | Complete example. Here we created five timers, you can run it and test the result in the Serial monitor and the onboard LED. 72 | 73 | ```cpp 74 | #include "TickTwo.h" 75 | 76 | void printMessage(); 77 | void printCounter(); 78 | void printCountdown(); 79 | void blink(); 80 | void printCountUS(); 81 | 82 | bool ledState; 83 | int counterUS; 84 | 85 | TickTwo timer1(printMessage, 0, 1); // once, immediately 86 | TickTwo timer2(printCounter, 1000, 0, MILLIS); // internal resolution is milli seconds 87 | TickTwo timer3(printCountdown, 1000, 5); // 5 times, every second 88 | TickTwo timer4(blink, 500); // changing led every 500ms 89 | TickTwo timer5(printCountUS, 100, 0, MICROS_MICROS); // the interval time is 100us and the internal resolution is micro seconds 90 | 91 | 92 | void setup() { 93 | pinMode(LED_BUILTIN, OUTPUT); 94 | Serial.begin(9600); 95 | delay(2000); 96 | timer1.start(); 97 | timer2.start(); 98 | timer3.start(); 99 | timer4.start(); 100 | timer5.start(); 101 | } 102 | 103 | void loop() { 104 | timer1.update(); 105 | timer2.update(); 106 | timer3.update(); 107 | timer4.update(); 108 | timer5.update(); 109 | if (timer4.counter() == 20) timer4.interval(200); 110 | if (timer4.counter() == 80) timer4.interval(1000); 111 | } 112 | 113 | void printCounter() { 114 | Serial.print("Counter "); 115 | Serial.println(timer2.counter()); 116 | } 117 | 118 | void printCountdown() { 119 | Serial.print("Countdown "); 120 | Serial.println(5 - timer3.counter()); 121 | } 122 | 123 | void printMessage() { 124 | Serial.println("Hello!"); 125 | } 126 | 127 | void blink() { 128 | digitalWrite(LED_BUILTIN, ledState); 129 | ledState = !ledState; 130 | } 131 | 132 | void printCountUS() { 133 | counterUS++; 134 | if (counterUS == 10000) { 135 | Serial.println("10000 * 100us"); 136 | counterUS = 0; 137 | } 138 | } 139 | ``` 140 | 141 | ## Documentation 142 | 143 | ### States 144 | 145 | ```cpp 146 | enum status_t { 147 | STOPPED, 148 | RUNNING, 149 | PAUSED 150 | }; 151 | ``` 152 | 153 | ### Constructors 154 | 155 | ```cpp 156 | TickTwo::TickTwo(fptr callback, uint32_t timer, uint16_t repeats, interval_t mode) 157 | ``` 158 | 159 | Creates a TickTwo object 160 | 161 | - **callback** for the function name you want to call 162 | - **timer** set the interval time in ms or us depending on mode 163 | - **repeats** set the number of repeats the callback should be executed, 0 is endless (default) 164 | - **mode** set the interval resolution to MILLIS, MICROS_MICROS or MICROS (default) 165 | 166 | **Example** 167 | 168 | ```cpp 169 | TickTwo timer(blink, 1000); // calls function blink() every second, internal resolution is micros, running endless 170 | TickTwo timer(blink, 1000, 5); // calls function blink() every second, internal resolution is micros, only 5 repeats 171 | TickTwo timer(blink, 1000, 0, MILLIS); // calls function blink() every second, internal resolution is millis, running endless 172 | TickTwo timer(blink, 1000, 0, MICROS_MICROS); // calls function blink() every 1000 microsecond, internal resolution is micros, running endless 173 | ``` 174 | 175 | ### Destructor 176 | 177 | ```cpp 178 | TickTwo::~TickTwo() 179 | ``` 180 | Destructor for Ticker object 181 | 182 | ## Class Functions 183 | 184 | ### TickTwo Start 185 | 186 | ```cpp 187 | void TickTwo::start() 188 | ``` 189 | 190 | Start the Ticker. Will count the interval from the moment that you start it. If it is paused, it will restart the Ticker. 191 | 192 | **Example** 193 | 194 | ```cpp 195 | timer.start(); 196 | ``` 197 | 198 | ### TickTwo Resume 199 | 200 | ```cpp 201 | void TickTwo::resume() 202 | ``` 203 | 204 | Resume the Ticker. If not started, it will start it. If paused, it will resume it. For example, in a Ticker of 5 seconds, if it was paused in 3 seconds, the resume in continue in 3 seconds. Start will set passed time to 0 and restart until get 5 seconds. 205 | 206 | **Example** 207 | 208 | ```cpp 209 | timer.resume(); 210 | ``` 211 | 212 | ### TickTwo Pause 213 | 214 | ```cpp 215 | void TickTwo::pause() 216 | ``` 217 | 218 | Pause the Ticker, so you can resume it. 219 | 220 | **Example** 221 | 222 | ```cpp 223 | timer.pause(); 224 | ``` 225 | 226 | ### TickTwo Stop 227 | 228 | ```cpp 229 | void TickTwo::stop() 230 | ``` 231 | 232 | Stop the Ticker. 233 | 234 | **Example** 235 | 236 | ```cpp 237 | timer.stop(); 238 | ``` 239 | 240 | ### TickTwo Update 241 | 242 | ```cpp 243 | void TickTwo::update() 244 | ``` 245 | 246 | Has to be called in the main while() loop, it will check the Ticker, and if necessary, will run the callback. 247 | 248 | **Example** 249 | 250 | ```cpp 251 | while(1) { 252 | timer.update(); 253 | 1. } 254 | ``` 255 | 256 | ### TickTwo set Interval Time 257 | 258 | ```cpp 259 | void TickTwo::interval(uint32_t timer) 260 | ``` 261 | 262 | Changes the interval time of the Ticker. Depending on the mode it can millis or micro seconds. 263 | 264 | - **timer** set the interval time in ms or us depending on mode 265 | 266 | 267 | **Example** 268 | 269 | ```cpp 270 | timer.interval(500); // new interval time 271 | ``` 272 | 273 | ### TickTwo get Interval Time 274 | 275 | ```cpp 276 | uint32_t TickTwo::interval() 277 | ``` 278 | 279 | Get the interval time of the Ticker. Depending on the mode it can millis or micro seconds. 280 | 281 | **Example** 282 | 283 | ```cpp 284 | uint32_t intervalTime; 285 | intervalTime = timer.interval(); // get the interval time 286 | ``` 287 | 288 | ### TickTwo State 289 | 290 | ```cpp 291 | status_t TickTwo::state() 292 | ``` 293 | 294 | Returns the state of the Ticker. 295 | 296 | **Example** 297 | 298 | ```cpp 299 | status_t status; 300 | status = timer.state(); 301 | ``` 302 | 303 | ### TickTwo Elapsed Time 304 | 305 | ```cpp 306 | uint32_t TickTwo::elapsed() 307 | ``` 308 | 309 | Returns the time passed since the last tick in ms or us depending on mode. 310 | 311 | **Example** 312 | 313 | ```cpp 314 | uint32_t elapse; 315 | elapse = timer.elapsed(); 316 | ``` 317 | 318 | ### TickTwo Remaining Time 319 | 320 | ```cpp 321 | uint32_t TickTwo::remaining() 322 | ``` 323 | 324 | Returns the remaining time to the next tick in ms or us depending on mode. 325 | 326 | **Example** 327 | 328 | ```cpp 329 | uint32_t remain; 330 | remain = timer.remaining(); 331 | ``` 332 | 333 | ### TickTwo Counter 334 | 335 | ```cpp 336 | uint32_t TickTwo::counter() 337 | ``` 338 | 339 | Get the number of executed callbacks. 340 | 341 | **Example** 342 | 343 | ```cpp 344 | uint32_t count; 345 | count = timer.counter(); 346 | ``` 347 | --------------------------------------------------------------------------------