// useing a push button
// to control a LED
int ledPin = 13;
int buttonPin = 12;
void setup() {
Serial.begin(9500);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// create a variable to store
// the "state" of the push button
int buttonState = digitalRead(buttonPin);
// the push button will give a reading
// of '1'->"true"->"HIGH"
// when it's not beeing pressed
// print the reading of the push button
// to the serial monitor
Serial.print("button state= ");
Serial.println(buttonState);
// turn the LED "on" when
// the push button reads "false"
if (buttonState == true) {
digitalWrite(ledPin, false);
}
//turn the LED "off" when
// the push button reads "true"
else {
digitalWrite(ledPin, true);
}
}