Getting an echo on the serial port
i send command "CMD1"
Micro should respond "SUC1"
But responce is
"CMD1
SUC1"
#define digitalPin2 2 // Port 2 for reading the door interlock state
#define digitalPin6 6 // Port 6 for Power LED on light field alignment
#define digitalPin8 8 // Port 8 for slecting dimming method
#define digitalPin10 10 // Port 10 for Green LED on filter
#define digitalPin12 12 // Port 12 for Green LED on filter
#define digitalPin13 13 // Port 13 for reading the push button on the light field module
int x =0;
int interlockstate=0;
int pushbuttonlightfield=0;
int analogPin = A0;
//ISR//float value = 100; //3035;
void setup()
{
Serial.begin(9600); //begin serial data
pinMode(digitalPin2, INPUT); // Port 2 for reading the interlock state
pinMode(digitalPin6, OUTPUT); // Port 6 for Power LED on light field alignment is an output
pinMode(digitalPin8, OUTPUT); // Port 8 for Dimming method select is an output
pinMode(digitalPin10, OUTPUT); // Port 10 for Green LED on filter is an output
pinMode(digitalPin12, OUTPUT); // Port 12 for Yellow LED on filter is an output
pinMode(digitalPin13, INPUT); // Port 13 for reading the push button on the light field module
//pin 13 is not on an interrrupt for state change so might need to change the switch
}
void loop()
{
delay (500); //rev 3, delay to slow system down
//Read this to see if the push button to turn on the LED is pushed or not
pushbuttonlightfield = digitalRead(digitalPin13);
// Serial.print("Push button state (0 is not pushed): ");
// Serial.println(pushbuttonlightfield);
//check if serial communication is avaiable
//then issue responce if command recognized
//using println rather than print so there is new line feed issued
//took this part from Filter recogition code
if (Serial.available() > 0) {
String rx_byte = Serial.readStringUntil('\n');
rx_byte.trim();
Serial.println(rx_byte);
if (rx_byte == "CMD1") {
digitalWrite(digitalPin12, LOW); // turn off Yellow LED in filter module
Serial.println("SUC1"); //CMD1 responce
}
if (rx_byte == "CMD2") {
digitalWrite(digitalPin12, HIGH); // turn on Yellow LED on filter module
Serial.println("SUC2"); //CMD2 responce
}
if (rx_byte == "CMD3") {
digitalWrite(digitalPin10, LOW); // turn on Green LED on filter module
Serial.println("SUC3"); //CMD2 responce
}
if (rx_byte == "CMD4") {
digitalWrite(digitalPin10, HIGH); // turn on Green LED on filter module
Serial.println("SUC4"); //CMD2 responce
}
if (rx_byte == "CMD5") {
digitalWrite(digitalPin8, LOW); // Set Dimming method to Analog
Serial.println("SUC5"); //CMD2 responce
}
if (rx_byte == "CMD6") {
digitalWrite(digitalPin8, HIGH); // Set Dimming method to Digital
Serial.println("SUC6"); //CMD2 responce
}
if (rx_byte == "CMD7") {
digitalWrite(digitalPin6, HIGH); // turn on Power LED on light field alignment module
Serial.println("SUC7"); //CMD2 responce
}
if (rx_byte == "CMD8") {
digitalWrite(digitalPin6, LOW); // turn off Power LED on light field alignment module
Serial.println("SUC8"); //CMD2 responce
}
if (rx_byte == "CMD9") {
interlockstate = digitalRead(digitalPin2); // 0 door open, 1 door closed
Serial.println(interlockstate); //(0 is door open)
}
}
}