Hello,
I stuck on this at my project. I want to print on my display analog values from potentiometer but i have issue like for example at the beginning i have number 8 ather that it increase to 1124 and at the and it decrease to 8 but on the display is 8124. How to fix this?
My code:
#include <LiquidCrystal_I2C.h>
int analog = 0;
LiquidCrystal_I2C lcd(0x3F, 16, 2);
void setup() {
lcd.begin();
lcd.backlight();
}
void loop() {
analog = analogRead(A1);
lcd.setCursor(0,0);
lcd.print(analog);
}
woodu:
Hello,
I stuck on this at my project. I want to print on my display analog values from potentiometer but i have issue like for example at the beginning i have number 8 ather that it increase to 1124 and at the and it decrease to 8 but on the display is 8124. How to fix this?
Formatting the number, so it always has four digits?
Leading zeros perhaps?
So you'd display value 8 as "0008" and value 1124 as "1124"?
Or maybe "leading spaces instead of leading zeros?
Or maybe trailing spaces?
value 8 would display as "8 " (three trailing spaces)
value 1124 would display as "1124" (no trailing spaces)
What do you think about formatting with leading zeros or leading /trailing spaces?
Clear the rest of the part the bigger numbers write to. Or, easy alternative, before writing anything clear the portion of the screen where the biggest number would go.
In this case that's 4 digits (1023 is the biggest possible number) so simply write 4 spaces on the same location where you want to print the value.