Adruino Lesson 3 – PA

Digital Input:

Serial Monitor:

Two Buttons One LED:

My Code:

const int buttonOn = 2; // the number of the pushbutton pin
const int buttonOff = 4;
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(buttonOn, INPUT);
pinMode(buttonOff, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonOn);
buttonState2 = digitalRead(buttonOff);
// 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);
}
}