int i, j;
char data;
int flag=0;
void loop()
{
if(Serial.available() > 0){
data = Serial.read();
flag=0;
}
if (data == 'd' && 'b') {
digitalWrite(cONOF, HIGH);
} else if (data == 't' && 'w') {
digitalWrite(cONOF, LOW);
}
if (data == 'y' && 'w') {
digitalWrite(start, HIGH);
delay(2000);
digitalWrite(start, LOW);
}
if (data == 'e' && 'r' && 'h' && 'i') {
for (i=0;i<10;i++) {
digitalWrite(horn, HIGH);
delay(100);
digitalWrite(horn, LOW);
delay(100);
}
for (j=0;j<10;j++) {
digitalWrite(horn, HIGH);
delay(500);
digitalWrite(horn, LOW);
delay(500);
}
digitalWrite(horn, LOW);
}
}
I want to read data from the USART where the messages have more than one character. I tried the code above but it doesn't work well. For example, I want to send the message 'db' to turn the output on, but just sending 'd' also turns it on, how do I fix this?