I'm building a bench top power supply with a TFT display. When text updates, it just writes over the old text, so the solution is to first have it place a rectangle the same color as the background, then write the text, which leads to flicker. I'm trying to write a sketch that will have three separate rectangles, since I have three decimal places, and only fill the rectangle of a digit if it changes.
I have the sketch below as a test, and it's breaking down the digits OK, but it's skipping one set. If I start with a value of 24.5, it's supposed to write to the serial monitor the whole value (24.5) then the next line the 2, next line the 4, next line the 5, then a line with a space, then the next set of numbers (24.4, etc).
What I'm getting back is as follows:
24.5
2
4
5
24.4
2
4
4
24.3
2
4
2
24.2
2
4
1
etc. The first two sets of numbers are correct, but then is writes 243. but never has a 2,4, and a 3. It skips to 2,4,2.
Even stranger is I plugged this into my TFT sketch to test it out and align the rectangles, and what that does is it displays the numbers correctly from 24.5 to 24.0, then at 23.9, it writes the 3 over the 4, but the tenths place displays correctly. Then when it gets to 23.0, it shows all three digits correctly, then writes a 2 over the 3, etc.
Below is my sketch:
float Volts;
int TenthsA;
int TenthsB;
int Tenths;
int VoltsA;
int OnesA;
int OnesConv;
int OnesConvB;
int Ones;
int Tens;
static float PresentVolts;
void setup() {
Serial.begin (9600);
//Test Data
Volts=25.0;
}
void loop() {
// Convert Tenths
PresentVolts = Volts;
TenthsA = PresentVolts;
TenthsB = TenthsA * 10;
Tenths = (PresentVolts * 10)-TenthsB;
// Convert Ones
VoltsA = PresentVolts;
OnesConv = VoltsA/10;
OnesConvB = OnesConv*10;
Ones = VoltsA-OnesConvB;
//Convert Tens
Tens=PresentVolts/10;
Serial.println (Volts,1);
Serial.println(Tens);
Serial.println (Ones);
Serial.println (Tenths);
Serial.println (" ");
delay (250);
Serial.println(" ");
Volts = Volts - .1;
if (Volts<0) {
Volts=25;
}
}