/* SN095 Code Modified by Paul Bradt Modification combines the Button with Blink code Description of Blink turns LED on and off with 1 sec interval Description of Button Code below: Button Code Turns on and off the on-Board light emitting diode (LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2. The circuit: - If using a separate LED needs to be attached from pin 13 to ground through 220 ohm resistor - pushbutton attached to pin 2 from +5V - Using PULLUP INPUT on Pin 2 so do not need resistor for pushbutton - Note: on most Arduinos there is already an LED on the board attached to pin 13. Button code created 2005 Original button code by DojoDave modified 30 Aug 2011 by Tom Igoe This example button code is in the public domain. https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button */ // constants won’t change. They’re used here to set pin numbers: const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin, 13 is the built in LED on an UNO R3 // variables will change: 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_PULLUP); //Using internal resistor to pullup voltage } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. If it is, the buttonState is LOW: if (buttonState == LOW) { // This is the code portion from Blink and blinks the LED every second while button is pushed digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); } else { // turn LED on: digitalWrite(ledPin, LOW); } }