#define LED_PIN 4
#define BUTTON_PIN 2
void setup(){
// Set the LED pin as output
pinMode(LED_PIN, OUTPUT);
// Set the button pin as input
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop(){
// Read the state of the button
int buttonState = digitalRead(BUTTON_PIN);
// If the button is pressed (LOW state), turn on the LED
if (buttonState == LOW){
digitalWrite(LED_PIN, HIGH);
} else {
// Otherwise, turn off the LED
digitalWrite(LED_PIN, LOW);
}
}
Loading
esp32-devkit-v1
esp32-devkit-v1