IF doesn't work
hi,
i have code:
the problem arduino does't goes throw if code. know data equal 1 because in line
but why data 1 doesn't pass if?
i have code:
quote
#define e1 8 // enable pin motor 1
#define i1 53 // control pin 1 motor 1
#define i2 52 // control pin 2 motor 1
#include <wire.h>
int status = 0;
char data;
void setup(){
serial.begin(57600);
//direction pins
pinmode(e1, output);
pinmode(i1, output);
pinmode(i2, output);
digitalwrite(e1, high);
}
void loop()
{
if (serial.available()){
data = char(serial.read());
serial.println(data);
serial.print("status:");
serial.println(status);
char test = 1;
if (data == test){
serial.println("funciona");
}
if(data == test || status==1){
digitalwrite(i1, high);
digitalwrite(i2, low);
status = 1;
}
if(char(data == 0) || status==0){
digitalwrite(i1, low);
digitalwrite(i2, low);
status = 0;
}
}
//more code
}
the problem arduino does't goes throw if code. know data equal 1 because in line
code: [select]
data = char(serial.read());
code wrote 1. i'm sending number 1 option getbytes rxtx java pluggin.but why data 1 doesn't pass if?
hi charlesblack
are expecting receive , compare character '1' (i.e. number 1 key on keyboard)?
if so, change statement be:
the single quote marks make value ascii code character 1. otherwise storing binary value 1.
regards
ray
are expecting receive , compare character '1' (i.e. number 1 key on keyboard)?
if so, change statement be:
code: [select]
char test = '1';
the single quote marks make value ascii code character 1. otherwise storing binary value 1.
regards
ray
Arduino Forum > Using Arduino > Programming Questions > IF doesn't work
arduino
Comments
Post a Comment