Week 9 – Yerkebulan Imanbayev

Concept:

For my digital sensors assignment, I used the sun and the moon as an inspiration. I used a yellow LED to represent the sun and a blue LED to represent the moon.

Implementation:

When the yellow button is pressed, the yellow LED – a.k.a. the Sun – lights up and when the blue button is pressed, the blue LED – a.k.a. the moon – lights up. When both buttons are pressed at the same time, they each blink and alternate for 1 second with an interval of 0.5 seconds, representing the cycle of the sun and the moon.

Circuit schematics: 

Video:

Code:

int yellowLED = 13; //labeling the digital output for the yellow LED
int blueLED = 9; //labeling the digital output for the blue LED

void setup() {
  pinMode(yellowLED, OUTPUT);
  pinMode(blueLED, OUTPUT);
  pinMode(A0, INPUT);
  pinMode(A2, INPUT);
}

void loop(){

  int switchPositionYellow = digitalRead(A0);
  int switchPositionBlue = digitalRead(A2);

  if (switchPositionYellow == HIGH) { //if the yellow button is pressed, the yellow LED is turned on
    digitalWrite(yellowLED, HIGH);
    digitalWrite(blueLED, LOW);
  }

  else if (switchPositionBlue == HIGH) { // if the blue button is pressed, the blue LED is turned on
    digitalWrite(yellowLED, LOW);
    digitalWrite(blueLED, HIGH);
  }

  else {
    digitalWrite(yellowLED, LOW); //if both buttons aren't pressed, the LEDs are turned off
    digitalWrite(blueLED, LOW);
  }

  if (switchPositionYellow == HIGH && switchPositionBlue == HIGH) { //if both buttons are pressed, 
                                                                    //both LEDS will blink and will alternate
    digitalWrite(yellowLED, HIGH); 
    delay(1000);                      
    digitalWrite(yellowLED, LOW);   
    delay(500);       

    digitalWrite(blueLED, HIGH);  
    delay(1000);                      
    digitalWrite(blueLED, LOW);   
    delay(500);       
  }
}

Future Improvements:

In the future, I want to uphold and develop the concept Moresby including an analog sensor that detects light. When the light shines, “the sun” – yellow LED – would turn on, and when the light does not shine, “the moon” – blue LED – would turn on.

Leave a Reply