IF doesn't work

Hi,

I have that code:

#define E1 8 // Enable Pin for motor 1
#define I1 53 // Control pin 1 for motor 1
#define I2 52 // Control pin 2 for 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 is that the arduino does’t goes throw the if code. I know that Data is equal to one because in this line Data = char(Serial.read()); the code wrote is 1. I’m sending the number one but the option getBytes with the RXTX Java Pluggin.

But Why with data as 1 doesn’t pass that if?

Hi charlesblack

Are you expecting to receive and compare the character '1' (i.e. the number 1 key on the keyboard)?

If so, change this statement to be:

char test = '1';

The single quote marks make the value into the ASCII code for the character 1. Otherwise you are storing the binary value 1.

Regards

Ray

Yes, I was writing the same that Hackscribble write.

Another thing, in the forum "code" is different of "quote". ;) Use "code" to put your code inside, is better to read.

Regards from Portugal!