SevSeg icon indicating copy to clipboard operation
SevSeg copied to clipboard

DisplayString() using no delays

Open joshnishikawa opened this issue 7 years ago • 1 comments

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.

joshnishikawa avatar Feb 07 '17 13:02 joshnishikawa

The most recent update fixes the decimal point.

joshnishikawa avatar Feb 11 '17 14:02 joshnishikawa