Wedding gift with e-card

Posted by tearkj

tearkj's picture

Description

Wedding gift with e-card : The wedding gift box has a embedded speaker and a light sensor, so when they open the box, it plays wedding song. Before and after the song it prints "congratulations" in the screen which can work as a e-card potentially.

movie

 

Material

Box, ribbon, photocell, piezo speaker, wedding card image

Code

/*
Wedding gift box
*/
 
int photo = 0;
int photoVal = 0;
 
int speakerPin = 7;
 
int count = 0;
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
int hold[] = {100, 112, 126, 134, 150, 169, 189, 200};
int note = 0;
int lastNote = 64;
byte melody[] = "CCCCbbbfaaggffddccccddddeeeeeeeeCCCCbbbfaaggffddccccdddeddddcccc";
int count3 = 0;
 
 
void setup() {
  pinMode(speakerPin, OUTPUT);
  Serial.begin(9600);
}
 
void loop() {
  digitalWrite(speakerPin, LOW);
  photoVal = analogRead(photo);
 
  if (photoVal > 10) {
    Serial.println(photoVal);
    for (note = 0; note <= lastNote; note++) {
     
      for (count = 0; count <= 8; count++) {
        if (melody[note] == names[count]) {
          for (int i = 0; i < hold[count]; i++) {
            digitalWrite(speakerPin, HIGH);
            delayMicroseconds(tones[count]);
            digitalWrite(speakerPin, LOW);
            delayMicroseconds(tones[count]);
          }
        } 
        else if (melody[note] == 'p') {
          digitalWrite(speakerPin, LOW);
          delay(20);
        }
      }
    }
  }
 
  else {
    Serial.println("congratulations");
  }
}
 

0
Your rating: None