I am trying to design a digital speedometer for use on a motorbike. I've got the code working, speed is calculated correctly, but I am having a small issue displaying it.
The display part of the code has to be put in the loop, since it's dynamic (value changes in time). This is where I encounter the issue - the first iteration of the code didn't clear the existing value and simply wrote over it - after a few minutes the digits all fused together into almost entirely filled rectangles - no good.
I then play about with drawing a black filled rectangle over the area - this indeed worked, but the flicker was unbearable - no good either.
I now am looking at a better option, following the advice from HERE - this seems to work great, however, only if the speed is a single digit. Once I venture into double digits, the first digit clears well, but the second one stays - so let's say I started at 0km/h, then sped up to 15 km/h, then immediately stopped - the display will show 0, then 15, then 05 - this is clearly an issue, as I'd like it to show just the 0.
Here is my section of the code that pertains to this specific issue:
You could overwrite only digits that changed when they changed. To do this you need to store last value and compare to the new value. You definitely don’t need to reprint the units of measure and other stuff that never changes
It really does not matter if you re-write the whole screen. This all takes place in the SRAM buffer. Nothing goes to the physical display until you call display.display();
So you will never notice any flicker. The changed pixels will just appear silently.
Follow the advice in #2. i.e. format the output nicely.
Use display.setTextColor(WHITE, BLACK); to ensure a fresh background is drawn when you write text.
Oh. #3 is the correct approach for drawing to an un-buffered display like a TFT. i.e. only re-draw areas that have changed. Use setTextColor(fg, bg) instead of separate fillRect(x, y, w, h, bg)
I have SSD1306 OLED and used it in a project which has high update rate of display value and no flicker because it updates only what needs to be updated. But thank you for sharing display method that I don’t even have.
I am sorry, you're going to have to be a bit slower with me! What's the advantage of that, other than its more elegant? I thought these screens don't print the areas if there's no change?