HI dear/users,
I have to built a logic using multiple string from serial port that must control the relay,
in my problem here what I am Entering the Simple X3 prints and no operation of counter
please help
/////////////////
#define RELAY 7
byte byteRead;
String data; //String sendData;
unsigned int count_up, count_down;
int FREQ, FREQ1;
float Time, Time1;
void setup()
{
Serial.begin(9600); // Turn the Serial Protocol ON
pinMode(LED_BUILTIN, OUTPUT);
//noTone(LED_BUILTIN);
pinMode(RELAY, OUTPUT);
digitalWrite(RELAY,LOW);
}
void loop()
{
while(Serial.available()>0) //check if data has been sent from the computer:
{ /* read the most recent byte */
data = Serial.readString();
if(data = "X3\n")
{
Serial.println(data);
//noTone(LED_BUILTIN);
digitalWrite(RELAY,HIGH);
delay(1000);
Serial.flush();
while(Serial.available()!= 0)
{
if(data == "X7\n")
{
Serial.println(data);
count_up = 1 + count_up;
FREQ = 100*count_up;
if((count_up >= 1)|(count_up <= 10))
{
tone(LED_BUILTIN, FREQ);
}
Serial.println("After pressing UP= ");
Serial.println(count_up,DEC);
Serial.println(FREQ,DEC);
}
else if(data == "X8\n")
{
Serial.println(data);
count_up = count_up -1;
FREQ = 100*count_up;
if((count_up >= 1)|(count_up <= 10))
{
tone(LED_BUILTIN, FREQ);
}
Serial.println("After pressing DOWN= ");
Serial.println(count_up,DEC);
Serial.println(FREQ,DEC);
}
if(count_up ==0)
{
noTone(LED_BUILTIN);
Serial.println("Now limit reaches to 'ZERO'");
}
}
}
Serial.flush();
}
}
/////////////////