I'm trying figure out how to make the serial monitor printing specific content based on the user input. For instance if the user has typed '1' it should constantly print ("Hello") and when user has typed '2' it should print ("Bye") and vice versa. I'm new to programming, so I would be grateful if any can help me with this.
String readString;
void setup()
{
Serial.begin(9600);
}
void loop()
{
if(Serial.available()>0)
{
char c = Serial.read();
readString +=c;
delay(2);
if (c == '1')
{
delay(1000);
Serial.println("Hello");
c = "";
}
if (c == '2')
{
delay(1000);
Serial.println("Bye");
c = "";
}
else
{
readString= "";
}
}
}