Hello Members
I am having problems in making my code understand my commands that I am sending through hyper terminal. Please find attached the code below and help me trouble shoot. I receive the initial introduction lines on the PC end but the "loop" is not responding to my commands.
#include <SoftwareSerial.h>
/-----( Declare Constants and Pin Numbers )-----/
#define Rx 10 //Serial Receive pin
#define Tx 11 //Serial Transmit pin
#define TxControl 3 //RS485 Direction control
#define Pin13LED 13
SoftwareSerial RSSerial(Rx, Tx); // RX, TX
/-----( Declare Variables )-----/
int byteReceived,val ;
byte A,B;
void setup() /****** SETUP: RUNS ONCE ******/
{
pinMode(Pin13LED, OUTPUT);
pinMode(TxControl, OUTPUT);
pinMode(Rx,INPUT);
pinMode(Tx, OUTPUT);
RSSerial.begin(9600); // set the data rate
digitalWrite(TxControl,HIGH);
RSSerial.write("Arduino UNO Live...\n");
RSSerial.write("Please Enter a valid command ...\n");
digitalWrite(TxControl,LOW);
while(RSSerial.read()>=0);
delay(2000);
}
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
val= RSSerial.available();
byte Command[] ={0,A,B};
while (val!=Command[1]||Command[2]);
{
digitalWrite(Pin13LED,HIGH);
delay(1000);
digitalWrite(Pin13LED,LOW);}
if (val ==Command[1]){
digitalWrite(TxControl,HIGH);
byteReceived= RSSerial.read();
RSSerial.write("byteReceived");
while(RSSerial.read()>=0);
digitalWrite(TxControl,LOW);
delay(1000);
}
else if (val ==Command[2]){
digitalWrite(TxControl,HIGH);
RSSerial.write("Inavalid");
while(RSSerial.read()>=0)
digitalWrite(TxControl,LOW);
delay(1000);}
}