So I last worked on making a while loop work, and now here's this problem-
In my while loop, I have it so if it does not read a command that says 4, it makes the LED blink, and if the command "4" has been given, it is supposed to make the while loop break.
So far, I have it in an if-else structure, so is there a way to make the Arduino read the last command sent (as in save the command that was sent via the serial and read it later)? Because Serial.read does not seem to work.
Here's the code, in case I am doing something else wrong-
void blinkmode(){
int blinkmodeon = 1;
while (blinkmodeon == 1)
{
if (Serial.available() > 0){
int command = Serial.read();
if (command == '4') {
blinkmodeon == 0;
}
}
else {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}
}