Problem on dividing, weird result
code: [select]
if (serial.available() > 1) {
delay(100); //mesaj gelsin
lcd.clear(); //lcd temizle
lcd.setcursor(0,0); // cursor 0,
for(i=0;i<2;i++) {
lcdinput[i] = serial.read();
}
if(lcdinput[0] == 'l') {
lcd.print("lightning ");
lightdata = lcdinput[1];
light = 255 / lightdata;
analogwrite(ledpin, light);
lcd.print(light);
this code. , lets say, sent l5 serial.
this should divide 255 5 , result should 51.
but keep getting 4. if convert light type float
they 4.20 4.70
btw:
float light;
int lightdata;
int lcdinput[2]; // buffer
any ideas ?
thanks
the ascii code 5 decimal 53. 255 / 53 = 4.8.
looks buffer storing integer values of characters.
looks buffer storing integer values of characters.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Problem on dividing, weird result
arduino
Comments
Post a Comment