// www.robotronix.co.il
// Embedded Systems Programming Course
// Robotics, Microcontrollers, Arduino and ESP32
#define led 4 // LED connected to GPIO 4
#define button 12 // Button connected to GPIO 12
int buttonState; // Store the button state
void setup() { // Run once at startup
Serial.begin(115200); // Start serial communication
Serial.println("System started"); // Print startup message
pinMode(button, INPUT_PULLUP); // Enable internal pull-up resistor
pinMode(led, OUTPUT); // Set LED pin as output
}
void loop() { // Run continuously
buttonState = digitalRead(button); // Read button state
if (buttonState == LOW) { // Check if button is pressed
Serial.println("LED ON"); // Print LED status
digitalWrite(led, HIGH); // Turn LED ON
}
if (buttonState == HIGH) { // Check if button is released
Serial.println("LED OFF"); // Print LED status
digitalWrite(led, LOW); // Turn LED OFF
}
delay(100); // Wait 100 ms
}