Light Wave Player

550

2

1

Materials

-4 LEDs

- a buzzer

-Jumper Wires

Step 1:

add the speaker on the breadboard and make sure they connect on both sides.

Step 2:

add all the wires in.

wire to ground hook up wires from pin one to pin 5.

Step 3:

hook up all the pins

make sure to follow all the steps in the picture and hook up the diodes and the buzzer. make sure the light bulb is placed in the specific area.

Step 4: Code

here is the coding

int speakerPin = 5;
int length = 26;

char notes[] = "eeeeeeegcde fffffeeeeddedg"; int beats[] = { 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};

int tempo = 300; 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[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };

int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

// play the tone corresponding to the note name

for (int i = 0; i < 8; i++) {

if (names[i] == note) {

playTone(tones[i], duration);

}

}

}

void setup() {

pinMode(speakerPin, OUTPUT);

pinMode(1,OUTPUT);

pinMode(2,OUTPUT);

pinMode(3,OUTPUT);

pinMode(4,OUTPUT); }

void loop() {

digitalWrite(1,LOW);

digitalWrite(2,LOW);

digitalWrite(3,LOW);

digitalWrite(4,LOW);

for (int i = 0; i < length; i++) {

if (notes[i] == ' ') {

digitalWrite(1,LOW);

digitalWrite(2,LOW);

digitalWrite(3,LOW);

digitalWrite(4,LOW);

delay(beats[i] * tempo); // rest

} else {

playNote(notes[i], beats[i] * tempo);

}

// pause between notes

delay(tempo / 2);

digitalWrite(1,HIGH);

digitalWrite(2,HIGH);

digitalWrite(3,HIGH);

digitalWrite(4,HIGH);

}

}

Step 5: Have Fun

Share

    Recommendations

    • Fandom Contest

      Fandom Contest
    • Frozen Treats Challenge

      Frozen Treats Challenge
    • Pets Challenge

      Pets Challenge

    Discussions

    0
    None
    Swansong

    1 year ago

    Good instructable, I'd love to see a video of it in play :)