LED [assignment 1]

For this assignment, I decided to create a game, where the player should navigate the motility, the distance by placing a hand or any object that will create shade in front of the photoresistor. The aim is to light up red and blue and yellow by placing hand and pressing button simultaneously which will light every color one by one thrice. That’s when the game is claimed to be won.

There are three led lights on the breadboard, three controlled by analog input, the photoresistor, which will control the light intensity of red and blue and yellow led lights. The three led lights will be controlled by digital input, the button, and under very specific circumstances. Three LED lights will light one by one when three led lights that are controlled by a photoresistor will light up, otherwise, it will not.

Blue and red LED lights have their own condition: very close to photoresistor or complete darkness makes blue one light up, a bit far from the photoresistor makes red one work, and distance right in the middle of blue and red LEDs’ range makes yellow light work. After both light up, by pressing a yellow button, three LED lights go one by one and it will blink one after the other thrice, indicating the game over condition.

The scheme:

The video:

The code:

int red = 3;  //analogRead          
int blue = 5;   //analogRead
int yellow = 7;  //digitalRead

int LDR = A2;
int SWITCH = A3;
int sensorValue;

void setup() {
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(yellow, OUTPUT);
  Serial.begin(9600);
}
void blink(){
  digitalWrite(yellow, HIGH);
  delay(100);
  digitalWrite(yellow, LOW);
  
  digitalWrite(red, HIGH);
  delay(100);
  digitalWrite(red, LOW);
  
  digitalWrite(blue, HIGH);
  delay(100);
  digitalWrite(blue, LOW);

  delay(200);
  
}
// the loop routine runs over and over again forever:
void loop() {
  
  sensorValue = analogRead(LDR);
  
  if(sensorValue < 620){
    analogWrite(blue, 255);
    analogWrite(red, 0);
    
  }
  else if(sensorValue > 620 and sensorValue < 660){
    analogWrite(blue, 255);
    analogWrite(red, 255);
    analogWrite(yellow,255);
   
  }
  else if(sensorValue > 660 and sensorValue < 700){
    analogWrite(blue, 0);
    analogWrite(red, 255);
    
  }
  else if(sensorValue > 700 and sensorValue < 800){
    analogWrite(blue, 0);
    analogWrite(red, 0);
    analogWrite(yellow,0);
  }
  else{
    analogWrite(blue, 0);
    analogWrite(red, 0);
    analogWrite(yellow,0);
  }

  
  
  if(digitalRead(SWITCH)==HIGH and digitalRead(yellow)==1 and digitalRead(blue)==1 and digitalRead(red)==1) {
    digitalWrite(yellow, HIGH);
    delay(600);
    blink();
    blink();
    blink();
  }
  else{
    digitalWrite(yellow, LOW);
  }
}

 

 

Leave a Reply