button 2 switch, 2LED - shaneno12/MTEC2280 GitHub Wiki

const int buttonPin1 = 2; // the number of the pushbutton pin 2 const int buttonPin2 = 3; // the number of the pushbutton pin 3 const int led1 = 13; // the number of the LED pin const int led2 = 12; // variables will change: int buttonState1 = 0; // variable for reading the pushbutton status int buttonState2 = 0;

void setup() { // initialize the LED pin as an output: pinMode(led1, OUTPUT); pinMode(led2, OUTPUT);
// initialize the pushbutton pin as an input: pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin2, INPUT);
}

void loop(){ // read the state of the pushbutton value: buttonState1 = digitalRead(buttonPin1); // read the state of the pushbutton value: buttonState2 = digitalRead(buttonPin2);

// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState1 == HIGH) {
// turn LED on:
digitalWrite(led1, HIGH);
} else { // turn LED off: digitalWrite(led1, LOW); } if (buttonState2 == HIGH) {
// turn LED on:
digitalWrite(led2, HIGH);
} else { // turn LED off: digitalWrite(led2, LOW); } }