Arduino Lesson 3

Another good time learning some more about Arduino. I got both the lessons to function and came up with some modifications to get a two button switch going. It’s a great break from some of the other work I have to do! Check out what I did here.

The code I used for my solution to the double button switch is as follows:

// set pin numbers:
const int buttonPin1 = 2;// the number of the pushbutton pin
const int buttonPin2 = 3;
const int ledPin = 13; // the number of the LED pin

// variables will change:
int buttonState1 = 0;// variable for reading the pushbutton status
int buttonState2 = 1;

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);
}

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

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