Xiaohan’s Arduino Homework 2

Digital Input

Serial Monitor

Analog Input

Arduino sketch [two buttons control one LED (on and off)]

const int  buttonPin1 = 2;    // the number of the pushbutton pin
const int  buttonPin2 = -3;
const int ledPin1 = 13;       //  the number of the LED pin


void setup() {
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2,INPUT);
  pinMode(ledPin1, OUTPUT);
 }


void loop() {
  // read the state of the pushbutton value:
    buttonState = digitalRead(buttonPin);
  
   if ((digitalRead(buttonPin1) == HIGH) && (digitalRead(buttonPin2) == LOW)) {
   digitalWrite(ledPin1,HIGH);
   }

   if ((digitalRead(buttonPin1) == LOW) && (digitalRead(buttonPin2)) == HIGH) {
   digitalWrite(ledPin1,LOW);
   }
}