Happy Birthday assignment

 

The aim of this week assignment  is to use one digital and one analog input. So, the whole story is about birthday cake. To switch on the leds you need to press the button(  digital input ),  after  you pressed the button they automatically start to turn on one after another. To “blow” on the candles i used photoresistor. You can use your finger or something else to close it and turn the leds off.

 

Scheme:

Picture:


Last version:

code:

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;
int led8 = 9;
int a;
int t1 = 600;
bool v;
int vpin = A0;
int buttonPin = 13;


void setup() {
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);

}

void loop() {
  int currentButtonState = digitalRead(buttonPin);

  if (currentButtonState == HIGH){
    
    for(int i=2; i<9; i++){
      
        digitalWrite(i, HIGH);
        delay(t1);
        digitalWrite(i+1, HIGH);
        delay(t1);
        digitalWrite(i+2, HIGH);
        delay(t1);
        a = 2;
        }
  }

  if  (a == 2) {
  
      int Value = analogRead(vpin);
      int mappedValue = map(Value, 10, 100, 0, 255);
      
      for(int i=2; i<9; i++){
       analogWrite(i, mappedValue);
      }

 }
}

 

Leave a Reply