hi, I need to make a program where I have buttons in the app on my phone and send them via HC-05 Bluetooth serial to Arduino. In Arduino, I have to make a condition in the condition. Example:
and the problem is that when I load "Button1" and then I want to press "Button3" 3 times in a row, it doesn't go through the first condition if (Serial.readString () == "Button1"), and I want, that it will be staying in (Serial.readString () == "Button1") condition unless I press button 2, the others will not be affected
first comment is that you don't want to read many times. Just once because once you've read it, it's gone from the Serial buffer.
String message = Serial.readString();
if (message == "Button1") {
} else if (message == "Button2") {
}
what it seems is that if you get Button1 then the next actions can only be Button3 or Button4
➜ you need some sort of state machine to handle this or your code will very quickly become spaghetti code
the other thing is that readString() will play tricks on you with timeout etc... I would suggest to study Serial Input Basics to understand how to listen to the Serial port