/* Button Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2. The circuit: - LED attached from pin 13 to ground through 220 ohm resistor - pushbutton attached to pin 2 from +5V - 10K resistor attached to pin 2 from ground - Note: on most Arduinos there is already an LED on the board attached to pin 13. created 2005 by DojoDave modified 30 Aug 2011 by Tom Igoe This example 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 buttonPin1 = 2; const int buttonPin2 = 4; const int buttonPin3 = 5; const int buttonPin4 = 6; const int buttonPin5 = 7; const int buttonPin6 = 8; const int buttonPin7 = 9; const int buttonPin8 = 10; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin // variables will change: int buttonState1 = HIGH; int buttonState2 = HIGH; // variable for reading the pushbutton status int buttonState3 = HIGH; int buttonState4 = HIGH; int buttonState5 = HIGH; int buttonState6 = HIGH; int buttonState7 = HIGH; int buttonState8 = HIGH; void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin1, INPUT); pinMode(buttonPin2, INPUT); pinMode(buttonPin3, INPUT); pinMode(buttonPin4, INPUT); pinMode(buttonPin5, INPUT); pinMode(buttonPin6, INPUT); pinMode(buttonPin7, INPUT); pinMode(buttonPin8, INPUT); } void loop() { // read the state of the pushbutton value: buttonState1 = digitalRead(buttonPin1); buttonState2 = digitalRead(buttonPin2); buttonState3 = digitalRead(buttonPin3); buttonState4 = digitalRead(buttonPin4); buttonState5 = digitalRead(buttonPin5); buttonState6 = digitalRead(buttonPin6); buttonState7 = digitalRead(buttonPin7); buttonState8 = digitalRead(buttonPin8); // check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (buttonState1 == LOW) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } if (buttonState2 == LOW) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } if (buttonState3 == LOW) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } if (buttonState4 == LOW) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } if (buttonState5 == LOW) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } if (buttonState6 == LOW) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } if (buttonState7 == LOW) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } if (buttonState8 == LOW) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } }