DisplayString() using no delays #14
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The DisplayString function has been updated to eliminate any delay.
Rather than iterating through the digits in a for loop every time the
function is called, this approach iterates on a static variable only
after a given time has elapsed regardless of how often the function is
called. In order to get this working while preserving all other
functionality (brightness, different numbers/types of digits, etc.) the
function has become a little harder to follow. Here it is in a nutshell.
//
static byte digit = 0;
if (time is up) //do something
if (digit == numberOfDigits +1) //only used when there's a colon
and/or apos
turn off the final digit //the one equal to numberOfDigits
turn on the colon and/or apos
digit = 0 //reset static variable for the next
cycle
set timer to brightness
else if (digit == numberOfDigits)
turn off previous digit
turn on final digit //the one equal to numberOfDigits
if (there's a colon) digit++ //is there a colon/apos?
else digit=0 //or should we reset?
set timer to brightness
else
if (digit == 0)
if (there's a colon/apos)
turn off colon/apos
else
turn off the final digit //the one equal to numberOfDigits
set timer to brightnessDelay
else
if (digit != 1); //digits that can be iterated upon
normally
turn off the previous digit
turn on the current digit
set timer to brightness
digit++;
else do nothing until time is up
//
The sections for turning digits/segments on and off have been broken out
into
void turnDigitOff(byte digit);
void turnDigitOn(char* toDisplay, byte digit);
Variables for keeping track of time have also been added.
unsigned long previousMicros, timer;
I hadn't originally intended to edit SetBrightness() but because the new
approach entirely foregoes the FRAMEPERIOD, I had to find a workaround.
I think it makes the code a bit cleaner and I haven't noticed any kind
of flickering but it's only been tested properly on a 4-digit display.