#define LED_PIN 13 // Define the pin connected to the LED (built-in LED is typically connected to pin 13)
char command; // Variable to store incoming command from Python
void setup() {
pinMode(LED_PIN, OUTPUT); // Set the LED pin as an output
Serial.begin(9600); // Initialize serial communication at 9600 baud rate
}
void loop() {
if (Serial.available() > 0) { // Check if data is available to read
command = Serial.read(); // Read the incoming command
if (command == 'a') { // If command is 'a' (turn on LED)
digitalWrite(LED_PIN, HIGH); // Turn on the LED
Serial.println("LED turned on"); // Send confirmation message back to Python
}
else if (command == 'b') { // If command is 'b' (turn off LED)
digitalWrite(LED_PIN, LOW); // Turn off the LED
Serial.println("LED turned off"); // Send confirmation message back to Python
}
}
}