WK8 – Meera:

int button = 2;
int ledY = 3;
int ledG = 5;
int ledB = 6;
int ledR = 4;
bool ledYState = false;
bool ledGState = false;
bool ledBState = false;
bool ledRState = false;
bool prevButtonState = LOW;
int knob = A0;
void setup() {
  pinMode  ( button, INPUT);
  pinMode ( ledY , OUTPUT);
  pinMode ( ledG, OUTPUT);
  pinMode ( ledB, OUTPUT);
  pinMode ( ledR, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int buttonState = digitalRead(button);
  Serial.println(buttonState);
  digitalWrite( ledY, ledYState);
  digitalWrite( ledG, ledGState);
  digitalWrite( ledB, ledBState);
  digitalWrite( ledR, ledRState);

  if (buttonState == HIGH && prevButtonState == LOW) {
    ledYState = !ledYState;
  }
  if (buttonState == HIGH && prevButtonState == LOW) {
    ledGState = !ledGState;
  }
  if (buttonState == HIGH && prevButtonState == LOW) {
    ledBState = !ledBState;
  }
  if (buttonState == HIGH && prevButtonState == LOW) {
    ledRState = !ledRState;
  }


  prevButtonState = buttonState;

  int knobValue = analogRead ( knob);

  if ( 300 < knobValue) {
    digitalWrite(ledG, HIGH);
    digitalWrite(ledB, HIGH);
    digitalWrite(ledY, LOW);
    digitalWrite(ledR, LOW);
  }
  else {
    digitalWrite(ledG, LOW);
    digitalWrite(ledB, LOW);
  }

  if ( 700 < knobValue) {
    digitalWrite(ledY, HIGH);
    digitalWrite(ledR, HIGH);
    digitalWrite(ledG, LOW);
    digitalWrite(ledB, LOW);
  }
  else {
    digitalWrite(ledY, LOW);
    digitalWrite(ledR, LOW);

  }
  Serial. println ( knobValue);

}

Wk8 : 

Knob alternation : 

MY FINAL TWIST WAS ADDING A HOUSE, I KNOW THE HOUSE DOESNT LOOK GREAT. HOWEVER, I THOUGHT IT GAVE PURPOSE TO THE LED SWITCH. IMAGINE WALKING INTO A HOUSE , TURNING ON THE LIGHT AND HAVING A SWITCH THAT CAN ALTERNATE BETWEEN THE LIGHTS YOU NEED. THIS IS WHAT I TRY TO DISPLAY IN THIS WEEKS ASSIGNMENT.

 

 

 

 

Leave a Reply