//Activity 2: LED + Button
// Constants
const int buttonPin = 7; // the pin number for the pushbutton
const int ledPin = 13; // the pin number for the LED
// Variables
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output
pinMode(buttonPin, INPUT_PULLUP); // initialize the pushbutton pin as an input
}
void loop() {
// read the state of the pushbutton value
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed
if (buttonState != HIGH) {
// turn on the LED
digitalWrite(ledPin, HIGH);
} else {
// turn off the LED
digitalWrite(ledPin, LOW);
}
}