Ok so I came to the point in my program when I would like to display IP address of the Ethernet shield stored as array of bytes :
byte ip[4] = { 192, 168, 0, 10 };
onto the DFROBOT LCD.
now this wasn't very easy because 2 print functions implemented in LCD4Bit_mod library are printing byte by byte either dec value or message
so lcd.print(65) will display A
and lcd.printIn("Abc") will display Abc
so to display int x = 1 as ASCII you should lcd.print(x + 48);
what about byte value like ip[1] = 192 ?
lcd.print(ip[1] + 48) will not work I promisse!
this is because 192 + 48 is 240 which is in ASCII table = ð
so what to do ?
split 192 into 1 + 48 , 9 + 48 and 2 + 48 and output byte by byte ?
hmmm ok ...
so I created function
lcdPrintIp(ip);
// which look like this:
void lcdPrintIp(byte ip_[])
{
lcd.clear();
lcd.print(ByteNA(ip_[0],3)); lcd.print(ByteNA(ip_[0],2)); lcd.print(ByteNA(ip_[0],1)); lcd.printIn(".");
lcd.print(ByteNA(ip_[1],3)); lcd.print(ByteNA(ip_[1],2)); lcd.print(ByteNA(ip_[1],1)); lcd.printIn(".");
lcd.print(ByteNA(ip_[2],3)); lcd.print(ByteNA(ip_[2],2)); lcd.print(ByteNA(ip_[2],1)); lcd.printIn(".");
lcd.print(ByteNA(ip_[3],3)); lcd.print(ByteNA(ip_[3],2)); lcd.print(ByteNA(ip_[3],1));
}
// and another one
byte ByteN(byte in, int n)
{
byte temp = in;
int i;
for(i = 1; i < n; i++){
if(i == n) break;
temp = temp / 10;
}
return (temp % 10);
}
// and one more
byte ByteNA(byte in, int n)
{
return (ByteN(in,n) + 48);
}
// by giving byte array like ip[], netmask[], gateway[] you are able now to display this onto LCD as ASCII
is this the simplest way ??? there must be another solution ?? :-?