#define BUTTON_PIN 7 // Button connected to pin 7
#define LED_PIN 13 // LED connected to pin 13
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP); // Button with internal pull-up resistor
pinMode(LED_PIN, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Start serial communication
}
void loop() {
if (Serial.available()) {
char command = Serial.read();
Serial.print("Received: ");
Serial.println(command);
if (command == 'E') {
digitalWrite(LED_PIN, HIGH); // Turn on LED
delay(500); // Keep LED on for 500ms
digitalWrite(LED_PIN, LOW); // Turn off LED
delay(500); // Keep it off for 500ms
}
}
if (digitalRead(BUTTON_PIN) == LOW) { // Button is pressed
Serial.println("A"); // Send 'A' to ESP32
delay(200); // Debounce delay
}
}