Been working on this programme today and have now got a bit of a problem.
I am sending the characters, 'A' and 'D' using XBee modules. When this data is received at the Arduino board I want to illuminate an LED. At the moment though when I send the data the LED lights up but does not turn off.
Code below;
int SignalRecieved = 10;
int TrainApproaching = 11;
int Fault = 12;
int BELL = 13;
int myData = 0;
void setup()
{
pinMode(SignalRecieved, OUTPUT);
pinMode(TrainApproaching, OUTPUT);
pinMode(Fault, OUTPUT);
pinMode(BELL, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (Serial.available()>0)
{
myData = Serial.read();
}
if (myData == 'D')
{
digitalWrite(SignalRecieved, HIGH);
digitalWrite(BELL, HIGH);
delay (1000);
digitalWrite(BELL,LOW);
delay (2000);
digitalWrite (TrainApproaching, LOW);
digitalWrite (Fault, LOW);
}
while (myData == 'A')
{
digitalWrite (TrainApproaching, HIGH);
digitalWrite(BELL, HIGH);
digitalWrite(SignalRecieved, LOW);
digitalWrite(Fault, LOW);
}
if (myData != 'A')
{
digitalWrite (Fault, HIGH);
digitalWrite(BELL, HIGH);
}
if (myData != 'D')
{
digitalWrite (Fault, HIGH);
digitalWrite(BELL, HIGH);
}
}
many thanks