I am trying to convert a code written for pic16f886 to Arduino. I am facing issues in string formatting. In PIC the code was
char look(int a){
switch(a){
case 0:
return '0';
case 1:
return '1';
case 2:
return '2';
case 3:
return '3';
case 4:
return '4';
case 5:
return '5';
case 6:
return '6';
case 7:
return '7';
case 8:
return '8';
case 9:
return '9';
default:
return '.';
}
}
unsigned int amps = 1835;
display_va(0, 0, 1835, 'A');
void display_va( char pos_row, char pos_col, unsigned int value, char type){
unsigned char va[] = "00.00 ";
va[0] = look(value/1000);
va[1] = look((value/100)%10);
va[3] = look((value/10)%10);
va[4] = look((value/1)%10);
va[5] = type;
Lcd_out(pos_row, pos_col, va);
this would print 18.35A starting at row 0 column 0. I am trying to achieve this in arduino. I tried
long amps = 00.00;
amps = 1835;
amps = 1835 / 100;
lcd.setCursor(0,0);
lcd.print(String(amps) + "A");
it prints 18.35A which is ok but if amps is 183 it prints 1.83AA. the previous "A" remains. one way would be to use If statement and delete the extra "A" if amps<1000. Is there a better way that the "A" would be fixed in the same column and numbers are displayed close to "A"
7 posts - 4 participants