Week 3 Homework

All the clips are here –>  https://photos.app.goo.gl/4PmetsURixDipdLZA

The circuit I made myself involves two buttons that control one LED, where pushing neither or both buttons would turn the light on and pushing either of the button would turn it off.

const int buttonPin0 = 2;    
const int buttonPin1 = 3;
const int ledPin =  13;     

int buttonState0 = 0;       
int buttonState1 = 0;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin0, INPUT);
  pinMode(buttonPin1, INPUT);
}

void loop() {
  buttonState0 = digitalRead(buttonPin0);
  buttonState1 = digitalRead(buttonPin1);

  if (buttonState0 == HIGH){
    if (buttonState1 == HIGH) {
      digitalWrite(ledPin, HIGH);
    }
    else {
      digitalWrite(ledPin, LOW);
    }
  }
  else {
    if (buttonState1 == HIGH) {
      digitalWrite(ledPin, LOW);
    }
    else {
      digitalWrite(ledPin, HIGH);
    }
  }
}
  
    

 

Author: Hui Zheng

From China. Product designer.