Just my observation. I compiled the helloWorld of liquidcrystals library
Original code 2616bytes!!
Comment the line lcd.print(number) 2034bytes ookye
Used Sprintf to generate string for number and comment the lcd.print(number) 3974bytes!!!
Add a lcd.print(string) with the above sprintf thing 4008bytes!!!!
So it seems that the lcd.print(number) costs 600bytes, while the lcd.print(string) only costs 35bytes. (include the function and one call)
The sprintf though, costs 1900bytes (include the function and one call)
If I want to output to lcd, the best way is to just output a string. The lcd.print(number) sucks anyway if you want to control on exact length.
But if you want exact say 4digits dot 2 digits, you need to use the sprintf, 1900 bytes, ouch!
Any light weight library that can take format string for just integers? Thanks.
By the way, I made this simple program that does one positive integer within 140 bytes of code. Maybe someone else has a better code that I can use. Here it is for sharing:
You provide your own buffer (6 bytes) and wipe it with empty space characters. Pass the end of the buffer-1 and the number, the program fills the buffer with a string representing the number.
int a[5]={7168, 4857, 8425, 4857, 138};
void setup()
{
Serial.begin(115200);
}
void loop()
{
char buffer[6];
for (byte j=0;j<5;j++)
{
for (byte i=0;i<5;i++)
{
buffer[i]=32;
}
buffer[5]=0;
toString(buffer+4, a[j]);
Serial.println(buffer);
delay(1000);
}
}
int toString(char* buf, int num)
{
int mynum=num;
if (num>=10)
{
*buf=mynum-toString(buf-1,num/10)+48;
}
else
{
*buf=num+48;
}
return(num*10);
}