Skip to content

Commit e34b969

Browse files
committed
Fix brightness stuck state
Fix for issue #50. If the waitOffTime was set to 0 while waitOffActive was true, then refreshDisplay would continuously return and never turn on any LEDs. The state would get stuck. This should no longer be possible.
1 parent 0e05816 commit e34b969

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ sevseg.blank();
140140
### Setting the brightness
141141

142142
```c++
143-
sevseg.setBrightness(240);
143+
sevseg.setBrightness(90);
144144
```
145145

146146
The brightness can be adjusted using a value between -200 and 200. 0 to 100 is the standard range.

SevSeg.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,16 @@ void SevSeg::begin(byte hardwareConfig, byte numDigitsIn, byte digitPinsIn[],
210210
void SevSeg::refreshDisplay() {
211211

212212
if (!updateWithDelays) {
213+
unsigned long us = micros();
213214

214215
// Exit if it's not time for the next display change
215216
if (waitOffActive) {
216-
if (micros() - prevUpdateTime < waitOffTime) return;
217-
prevUpdateTime = micros();
217+
if (us - prevUpdateTime < waitOffTime) return;
218218
}
219-
220-
if (micros() - prevUpdateTime < ledOnTime) return;
221-
prevUpdateTime = micros();
219+
else {
220+
if (us - prevUpdateTime < ledOnTime) return;
221+
}
222+
prevUpdateTime = us;
222223

223224
if (!resOnSegments) {
224225
/**********************************************/
@@ -367,6 +368,7 @@ void SevSeg::setBrightness(int brightness) {
367368
if (brightness > 0) {
368369
ledOnTime = map(brightness, 0, 100, 1, 2000);
369370
waitOffTime = 0;
371+
waitOffActive = false;
370372
}
371373
else {
372374
ledOnTime = 0;

0 commit comments

Comments
 (0)