Right adjust number on LCD
i want right adjust number within block. number can between 1 , 3 digits long, , 1s, 10s, , hundreds place stay in consistent spot on lcd screen. right code have doing this:
i'm wondering if there's more elegant way figure out how many digits number has without using logrithms.
code: [select]
int offset = ceil(log(rms+1)/log(10));
if( offset==0 ) offset = 1;
lcd.clear();
lcd.setcursor( 13-offset, 1 );
lcd.print( rms );
lcd.print( " mw" );
i'm wondering if there's more elegant way figure out how many digits number has without using logrithms.
code: [select]
void setup()
{
serial.begin(115200);
(int anumber = 0; anumber < 110; anumber++)
{
padnumber(anumber);
serial.println(anumber);
}
}
void loop()
{
}
void padnumber(int numbertopad)
{
if (numbertopad < 10)
{
serial.print("0");
}
if (numbertopad < 100)
{
serial.print("0");
}
}
Arduino Forum > Using Arduino > Programming Questions > Right adjust number on LCD
arduino
Comments
Post a Comment