Skip to content

DisplayString() using no delays #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

joshnishikawa
Copy link

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.

monkeybiscuits added 2 commits February 7, 2017 22:49
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.
previous update caused the decimal point to stop working.
@joshnishikawa
Copy link
Author

The most recent update fixes the decimal point.

sometimes a lower case 'a' looks better
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant