*/
// constants won't change. They're used here to set pin numbers: char buttonChar1 = 'a'; // the number of the pushbutton pin const int buttonPin1 = 2; const int buttonPin2 = 3; const int buttonPin3 = 4; const int buttonPin4 = 5; const int buttonPin5 = 6; const int ledPin = 13; // the number of the LED pin
// variables will change: int buttonState1 = 0; // variable for reading the pushbutton status int buttonState2 = 0; int buttonState3 = 0; int buttonState4 = 0; int buttonState5 = 0; int pinsArray[5] = {2, 3, 4, 5, 6}; 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); }
void loop() { // read the state of the pushbutton value: buttonState1 = digitalRead(buttonPin1) == 2; buttonState2 = digitalRead(buttonPin2) == 3; buttonState3 = digitalRead(buttonPin3) == 4; buttonState4 = digitalRead(buttonPin4) == 5; buttonState5 = digitalRead(buttonPin5) == 6; // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
switch (pinsArray[5]) { case 2: // digitalWrite(ledPin, HIGH); Serial.println("button1"); break; case 3: // digitalWrite(ledPin, HIGH); Serial.println("dim"); break; case 4: // Serial.println("medium"); break; case 5: // Serial.println("bright"); break; } }
*/
// constants won't change. They're used here to set pin numbers:
char buttonChar1 = 'a'; // the number of the pushbutton pin
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4;
const int buttonPin4 = 5;
const int buttonPin5 = 6;
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int pinsArray[5] = {2, 3, 4, 5, 6};
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);
}
void loop() {
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1) == 2;
buttonState2 = digitalRead(buttonPin2) == 3;
buttonState3 = digitalRead(buttonPin3) == 4;
buttonState4 = digitalRead(buttonPin4) == 5;
buttonState5 = digitalRead(buttonPin5) == 6;
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
switch (pinsArray[5]) {
case 2: //
digitalWrite(ledPin, HIGH);
Serial.println("button1");
break;
case 3: //
digitalWrite(ledPin, HIGH);
Serial.println("dim");
break;
case 4: //
Serial.println("medium");
break;
case 5: //
Serial.println("bright");
break;
}
}