Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
sstaub committed Mar 5, 2021
1 parent 931f1d0 commit 8b6e18a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool ledState;
int counterUS;

Ticker timer1(printMessage, 0, 1); // once, immediately
Ticker timer2(printCounter, 1000, MILLIS); // internal resolution is milli seconds
Ticker timer2(printCounter, 1000, 0, MILLIS); // internal resolution is milli seconds
Ticker timer3(printCountdown, 1000, 5); // 5 times, every second
Ticker timer4(blink, 500); // changing led every 500ms
Ticker timer5(printCountUS, 100, 0, MICROS_MICROS); // the interval time is 100us and the internal resolution is micro seconds
Expand Down Expand Up @@ -163,7 +163,10 @@ Creates a Ticker object
**Example**
```cpp
Tickers timer(blink, 1000); // calls function blink() every second
Tickers timer(blink, 1000); // calls function blink() every second, internal resolution is micros, running endless
Tickers timer(blink, 1000, 5); // calls function blink() every second, internal resolution is micros, only 5 repeats
Tickers timer(blink, 1000, 0, MILLIS); // calls function blink() every second, internal resolution is millis, running endless
Tickers timer(blink, 1000, 0, MICROS_MICROS); // calls function blink() every 1000 microsecond, internal resolution is micros, running endless
```

### Destructor
Expand Down
25 changes: 8 additions & 17 deletions Ticker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,14 @@ void Ticker::update() {
}

bool Ticker::tick() {
if (!enabled) return false;
if (resolution == MILLIS) {
if ((millis() - lastTime) >= timer) {
lastTime = millis();
if (repeat - counts == 1) enabled = false;
counts++;
return true;
}
}
else {
if ((micros() - lastTime) >= timer) {
lastTime = micros();
if (repeat - counts == 1) enabled = false;
counts++;
return true;
}
}
if (!enabled) return false;
uint32_t currentTime = (resolution == MILLIS) ? millis() : micros();
if ((currentTime - lastTime) >= timer) {
lastTime = currentTime;
if (repeat - counts == 1 && counts != 0xFFFFFFFF) enabled = false;
counts++;
return true;
}
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/Ticker/Ticker.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bool ledState;
int counterUS;

Ticker timer1(printMessage, 0, 1);
Ticker timer2(printCounter, 1000, MILLIS);
Ticker timer2(printCounter, 1000, 0, MILLIS);
Ticker timer3(printCountdown, 1000, 5);
Ticker timer4(blink, 500);
Ticker timer5(printCountUS, 100, 0, MICROS_MICROS);
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "git",
"url": "https://github.com/sstaub/Ticker"
},
"version": "4.0.0",
"version": "4.1.0",
"frameworks": "arduino",
"platforms": "*"
}
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Ticker
version=4.0.0
version=4.1.0
author=Stefan Staub
maintainer=Stefan Staub <email@domain.com>
sentence=A library for creating Tickers which can call repeating functions. Replaces delay() with non-blocking functions.
Expand Down

0 comments on commit 8b6e18a

Please sign in to comment.