const int ledPin = 13; // Use the built-in LED
void setup() {
pinMode(ledPin, OUTPUT); // Initialize the LED pin as output
Serial.begin(115200); // Initialize serial communication
// Print instructions to the Serial Monitor
Serial.println("LED Control Commands:");
Serial.println(" 1 - Turn LED ON");
Serial.println(" 2 - Turn LED OFF");
Serial.println(" 3 - Blink LED 5 times");
Serial.println(" ? - Print this menu again");
Serial.println();
}
void loop() {
// Check if data is available to read from the Serial Monitor
if (Serial.available() > 0) {
char command = Serial.read(); // Read the incoming byte
// Use a switch statement to decide what to do based on the character received
switch (command) {
case '1':
digitalWrite(ledPin, HIGH);
Serial.println("Command: LED turned ON");
break;
case '2':
digitalWrite(ledPin, LOW);
Serial.println("Command: LED turned OFF");
break;
case '3':
Serial.println("Command: Blinking 5 times...");
for (int i = 0; i < 5; i++) {
digitalWrite(ledPin, HIGH);
delay(250);
digitalWrite(ledPin, LOW);
delay(250);
}
Serial.println("Finished blinking!");
break;
case '?':
// It's good practice to reprint the menu if the user is lost
Serial.println("Commands: 1 (ON), 2 (OFF), 3 (BLINK), ? (HELP)");
break;
default:
// This runs if the command doesn't match any case
Serial.println("Send '?' for help.");
break;
}
}
}