PROJECT 1: The contraption

Here is a video of my contraption.



The contraption did not turn out visually how I expected, it was difficult to build around the breadboard and microcontroller. I'm satisfied with the aesthetics of the device regardless. Here are some additional photos:





And here is my final code:

const int buttonPin1 = 4;   
const int green =  8;   

const int buttonPin2 = 2;   
const int yellow =  9;

const int buttonPin3 = 3;   
const int red =  10;
   
// variables will change:
int buttonState1 = 0;       

int buttonState2 = 0;

int buttonState3 = 0;

int RED = 0;
int YELLOW = 0;
int GREEN = 0;

void setup() {
  Serial.begin(9600);

  pinMode(green, OUTPUT);
  pinMode(buttonPin1, INPUT);

  pinMode(yellow, OUTPUT);
  pinMode(buttonPin2, INPUT);

  pinMode(red, OUTPUT);
  pinMode(buttonPin3, INPUT);
}

void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);

  if (buttonState1 == HIGH && buttonState2 == LOW && buttonState3 == LOW) {
    digitalWrite(green, HIGH);
    GREEN = 1;
  }

   if (buttonState1 == LOW && buttonState2 == HIGH && buttonState3 == LOW) {
    digitalWrite(red, HIGH);
    RED = 1;
  }

     if (buttonState1 == LOW && buttonState2 == HIGH && buttonState3 == HIGH) {
    digitalWrite(yellow, HIGH);
    YELLOW = 1;
  }
 
   if (buttonState1 == LOW && buttonState2 == LOW && buttonState3 == HIGH) {
    digitalWrite(green, LOW);
    GREEN = 0;
  }

   if (buttonState1 == HIGH && buttonState2 == HIGH && buttonState3 == LOW) {
    digitalWrite(red, LOW);
    RED = 0;
  }

   if (buttonState1 == HIGH && buttonState2 == LOW && buttonState3 == HIGH) {
    digitalWrite(yellow, LOW);
    YELLOW = 0;
  }

   if (buttonState1 == HIGH && buttonState2 == HIGH && buttonState3 == HIGH) {
    digitalWrite(green, LOW);
    digitalWrite(yellow, LOW);
    digitalWrite(red, LOW);
    RED=0;
    GREEN=0;
    YELLOW=0;
  }

//flash sequence
  if(RED == 1 && YELLOW == 1 && RED == 1){
  digitalWrite(green, HIGH);
  digitalWrite(yellow, HIGH);
  digitalWrite(red, HIGH);
    delay(100);
  digitalWrite(green, LOW);
  digitalWrite(yellow, LOW);
  digitalWrite(red, LOW);
    delay(100);
  digitalWrite(green, HIGH);
  digitalWrite(yellow, HIGH);
  digitalWrite(red, HIGH);
    delay(100);
  digitalWrite(green, LOW);
  digitalWrite(yellow, LOW);
  digitalWrite(red, LOW);
    delay(100);
  digitalWrite(green, HIGH);
  digitalWrite(yellow, HIGH);
  digitalWrite(red, HIGH);
    delay(100);
  digitalWrite(green, LOW);
  digitalWrite(yellow, LOW);
  digitalWrite(red, LOW);
     delay(100);
  digitalWrite(green, HIGH);
  digitalWrite(yellow, HIGH);
  digitalWrite(red, HIGH);
    delay(100);
  digitalWrite(green, LOW);
  digitalWrite(yellow, LOW);
  digitalWrite(red, LOW);
    delay(100);
  digitalWrite(green, HIGH);
  digitalWrite(yellow, HIGH);
  digitalWrite(red, HIGH);
    delay(100);
  digitalWrite(green, LOW);
  digitalWrite(yellow, LOW);
  digitalWrite(red, LOW);
    delay(100);
  digitalWrite(green, HIGH);
  digitalWrite(yellow, HIGH);
  digitalWrite(red, HIGH);
    delay(100);
  digitalWrite(green, LOW);
  digitalWrite(yellow, LOW);
  digitalWrite(red, LOW);
    delay(100);
  digitalWrite(green, HIGH);
  digitalWrite(yellow, HIGH);
  digitalWrite(red, HIGH);
    delay(100);
  digitalWrite(yellow, LOW);
  digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  RED=0;
  YELLOW=0;
  GREEN=0;
 }

}

Comments

Popular posts from this blog

PROJECT 1 (2.0!) : LOCK BOX (For 3/26/19)

Project one observations