Birdlesque

Submitted by syh on Tue, 04/02/2013 - 15:42

Description:
A very pretty bird peeps out on her stage when the curtains open. As the photocell in her hat senses that she is in the light, the LEDs in her bikini top turn on to attract attention, and she sings "La Vie en Rose." Her stage is propped up with wood and can be controlled using a servo motor.

 

Components:
 - 1 box
 - 1 crocheted bird
 - pieces of felt and conductive thread
 - 2 red LEDs
 - 2 220-ohm resistors
 - 1 photocell
 - 1 10k-ohm resistor
 - 1 piezo speaker
 - 2 Arduino Unos
 - 2 breadboards
 - flat piece of balsa wood, plus supporting pieces to prop it up
 - small pieces of balsa wood, acting as "arms"
 - pins and tape to hold the wood together
 - 2 pieces of t-shirt cotton for curtains
 - 4 bobbins
 - yarn (works with bobbins to make the curtain)

 

Code:

Photocell-controlled heartbeat-like blinking:

/*
  Very basic code to use photocell readings and set an LED to blink.
*/
 
 
//sensor inputs
int sensorLight = 0;
 
//LED outputs
int led1 = 10;
int led2 = 11;
 
int brightness = 0;
 
void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  Serial.begin(9600);
}
 
void loop()
{
  brightness = analogRead(sensorLight);
  Serial.println(brightness);
  
  if(brightness > 0)
  {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    delay(500);
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    delay(500);
    digitalWrite(led1,  HIGH);
    digitalWrite(led2, HIGH);
    delay(1000);
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    delay(1500);
  }
}
 
La Vie en Rose:
int speakerPin = 7;
//int potPin = 0;   // select the input pin for the potentiometer
//int motorPin = 9; // select the pin for the Motor
//int val = 0;      // variable to store the value coming from the sensor
int length = 97; // the number of notes
char notes[] = "cbagEcbagECbagEBCcagdcbafcbagfDbagfVDbagcbagEcbagECbagEBCccddcddcddcgddcddcddcedcbagEcbagECbagabc"; // a space represents a rest
int beats[] = {3,1,1,1,1,1,3,1,1,1,1,1,3,1,1,1,1,1,2,2,3,1,1,1,1,1,3,1,1,1,1,1,3,1,1,1,1,1,2,2,8,1,2,1,1,2,1,1,2,1,4,1,2,1,1,2,1,1,2,1,2,2,3,1,1,1,1,1,3,1,1,1,1,1,3,1,2,2,6,};
int tempo = 90;
 
void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}
 
void playNote(char note, int duration) {
  char names[] = { 'B', 'C', 'V', 'D', 'E', 'f', 'g', 'a', 'b', 'c', 'd', 'e',};
  int tones[] = { 4050, 3822, 3608, 3405, 3034, 2863, 2551, 2273, 2025, 1915, 1700, 1519,};
 
  // play the tone corresponding to the note name
  for (int i = 0; i < 14; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}
 
void setup() {
  pinMode(speakerPin, OUTPUT);
  //pinMode (motorPin, OUTPUT); //I have to put this or else it won't work
  //Serial.begin(9600);
}
 
void loop() {
  //val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024 
  //Serial.println(val);
  //analogWrite(motorPin, val/4); // analogWrite can be between 0-255
  
  for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest GET RID OF DELAY
    } 
    else {
      playNote(notes[i], beats[i] * tempo);
     
    }
    delay(tempo / 2); // pause between notes GET RID OF DELAY
  }
 
    
}

 

IMG_20130402_153701.jpg
IMG_20130402_153934.jpg
IMG_20130402_153945.jpg
0
Your rating: None
Drupal theme by Kiwi Themes.