/*
=== Task 1 - Pull-Up Button LED Using if ===
Author: Roberto Palozzo
============================================
*/
int pushButton = 4;
int ledPin = 2;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-S3!");
pinMode(pushButton, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
int buttonState = digitalRead(pushButton); // Read the current button state.
// Check whether the button is pressed.
if (buttonState == LOW) {
digitalWrite(ledPin, HIGH);
Serial.println("Button pressed - LED On");
}
if (buttonState == HIGH){
digitalWrite(ledPin, LOW);
Serial.println("Button released - LED Off");
}
delay(100);
}