Hi!
I'm using this routine to display a integer on the LCD.
But it counts wrong when the integer is more than 100
(displays 100 as 101 and 101 as 102 etc)
can somebody help me to get it right?
// checks out how many digits there are in a number
int estimateDigits(int nr) {
int dec = 10;
int temp = 1;
int div = nr/dec;
while (div > 0) {
dec *= 10;
div = nr/dec;
temp++;
}
return temp;
}
// shows numbers on the display
void LcdNumberWrite(int nr) {
int digits = estimateDigits(nr);
LcdNumberWrite(nr, digits);
}
// this function help us to write numbers
// with more than one digit
void LcdNumberWrite(int nr, int digits) {
for (int i = digits-1; i >= 0; i--) {
int dec = pow(10,i);
int div = nr/dec;
lcd.print(div+48);
if (div > 0) {
nr -= div*dec;
}
}
}