/* LightSwitchPullup2a Turn an LED on and off. Internal pullup version. */ const int pushButtonPin = 2; // connect the push button to digital pin 2 const int ledPin = 13; // connect the LED to pin 13 boolean buttonState; // stores current button state void setup() { pinMode(pushButtonPin, INPUT); // make the pushbutton's pin an input digitalWrite(pushButtonPin, HIGH); // turn on internal pullup resistors pinMode(ledPin, OUTPUT); // make LED's pin an output } void loop() { buttonState = digitalRead(pushButtonPin); // read the input pin // set LED state accordingly // note the inverted logic resulting from using pullup resistors. digitalWrite(ledPin, !buttonState); // turn the LED on or off }