Great - glad it helped! It does look good - I can only imagine what it looked like before. Hopefully you picked up a lesson or two in working with the code. The function usage and make sure you
understand the elapsedMillis it is a very useful way to avoid delay() and may be useful in other places, for instance you could use it to reduce the reads from the CANbus if you are calling too often.
I like your commenting style
Indeed as long as only the fgc changes you can do what you want with that and the bgc will keep it clean just the same.
One thing could be done to have the code be 2/3'rds cleaner (but work the same) would be to move the case specific conditional from before the call into the function, and also allowing getting rid of the intermediate 'newXXX' variables too :
Code:
[U] newMAP = MAP / 10;
if ( newMAP != oldMAP )[/U]
oldMAP = tftSCprintF(oldMAP, [B]newMAP[/B], ILI9341_BLUE, ILI9341_BLACK, 235, 105);
float tftSCprintF( float oldV, float newV, uint16_t fgc, uint16_t bgc, int xxt, int yyt ) {
tft.setCursor(xxt, yyt);
...
return newV;
}
could become:
Code:
oldMAP = tftSCprintF(oldMAP, [B][U]MAP / 10[/U][/B], ILI9341_BLUE, ILI9341_BLACK, 235, 105);
float tftSCprintF( float oldV, float newV, uint16_t fgc, uint16_t bgc, int xxt, int yyt ) {
[U] if ( oldV == newV ) return newV;[/U]
tft.setCursor(xxt, yyt);
tft.setTextColor(bgc);
tft.print(oldV);
tft.setCursor(xxt, yyt);
tft.setTextColor(fgc);
tft.print(newV);
return newV;
}