// Define the pins for LED and push button
const int ledPin = A4; // Analog pin for LED
const int buttonPin = 3; // Digital pin for push button
// Initialize LED state
bool ledState = LOW;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP); // Use internal pull-up resistor
}
void loop() {
// Read button state
bool buttonPressed = digitalRead(buttonPin) == LOW;
// Toggle LED based on button press
if (buttonPressed) {
ledState = !ledState;
analogWrite(ledPin, ledState ? 255 : 0); // Turn LED on or off
}
}