/* * Lab 1 - Task 1: LED Control with Delay()
* Objective: Turn on LED for 2 seconds when button is pressed.
*/
const int buttonPin = 4; // Push button connected to GPIO 4
const int ledPin = 2; // Built-in LED / External LED on GPIO 2
int buttonState = 0; // Variable for reading the pushbutton status
void setup() {
// Initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// Initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(115200); // Start serial communication
Serial.println("Task 1 Ready: Press the button...");
}
void loop() {
// Read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// Check if the pushbutton is pressed (Assuming Active LOW)
if (buttonState == LOW) {
Serial.println("Button Pressed! LED ON for 2 seconds.");
digitalWrite(ledPin, HIGH); // Turn LED on
delay(2000); // Wait for 2 seconds (Blocking)
digitalWrite(ledPin, LOW); // Turn LED off
Serial.println("LED OFF. System resumed.");
}
}