Im trying to use a magnetometer to send a heading via XBEES to another arduino that then relays that heading through the RX pin of an arduino UNO controlling 2 LEDS. I want the LED on pin 12 to come on if the heading is less than 45 and the led on pin 11 to come on if the heading is greater than 45. For some reason its not working and i cant for the life of my understand why. any help on getting the Serial.read() data to be usable in my if statements would be greatly appreciated.
int heading = 0; // for incoming serial data
void setup() {
Serial.begin(57600); // opens serial port, sets data rate to 9600 bps
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
// send data only when you receive data:
if (Serial.available()>0 ) {
// read the incoming byte:
heading = (int) Serial.read();
if(heading > 45){
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
}else if(heading < 45){
digitalWrite(12, HIGH);
}
// say what you got:
// Serial.print("Fio received: ");
Serial.write(heading);
// Serial.write(10);
}
}