Hi all,
I am extremely new to coding/arduino.
Below shows some code I have made, but I have a problem.
Once the board is in the "blinking" state, I want to be able to type "on" or "off" to stop the loop.
How do I do this? (Sorry for my ignorance, I have search the net but can't seem to find anything applicable)
Thanks for your time!
Nick
String ByteReceived;
void setup()
{
Serial.begin(9600);
Serial.println(" To turn the on-board light on type 'on', to turn off type 'off' ");
Serial.println("Alternatively, type 'blink' to flash the light");
Serial.println();
pinMode(LED_BUILTIN,OUTPUT);
}
void loop()
{
if (Serial.available() > 0)
{
ByteReceived = Serial.readString();
if(ByteReceived == "on")
{
Serial.println(ByteReceived);
digitalWrite(LED_BUILTIN,HIGH);
Serial.print(" LED ON ");
}
else if(ByteReceived == "off")
{
Serial.println(ByteReceived);
digitalWrite(LED_BUILTIN,LOW);
Serial.print(" LED OFF");
delay(1000);
}
else if(ByteReceived =="blink")
{
Serial.println("blinking");
do
{
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
delay(500);
} while(ByteReceived = "blink");
}
else
{
Serial.print("Invalid response!");
}
Serial.println(); // End the line
}
}