Plays the happy birthday song music on the speaker.

Dependencies:   DebounceInterrupts mbed

Committer:
bhakti08
Date:
Tue Jun 10 21:53:29 2014 +0000
Revision:
0:33ad8330e62d
Happy Birthday Song using mbed;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bhakti08 0:33ad8330e62d 1 /****************************************************************************************/
bhakti08 0:33ad8330e62d 2 /* IO DEVICES ASSIGNMENT 6 */
bhakti08 0:33ad8330e62d 3 /*This program uses the PWM output to generate a "HAPPY BIRTHDAY" Tone on the speaker */
bhakti08 0:33ad8330e62d 4 /****************************************************************************************/
bhakti08 0:33ad8330e62d 5
bhakti08 0:33ad8330e62d 6 #include "mbed.h"
bhakti08 0:33ad8330e62d 7
bhakti08 0:33ad8330e62d 8 // ms
bhakti08 0:33ad8330e62d 9 #define A4 440
bhakti08 0:33ad8330e62d 10 #define B4b 446
bhakti08 0:33ad8330e62d 11 #define C4 261
bhakti08 0:33ad8330e62d 12 #define C4_1 130
bhakti08 0:33ad8330e62d 13 #define C5 523
bhakti08 0:33ad8330e62d 14 #define D4 293
bhakti08 0:33ad8330e62d 15 #define D4b 277
bhakti08 0:33ad8330e62d 16 #define E4 329
bhakti08 0:33ad8330e62d 17 #define F4 349
bhakti08 0:33ad8330e62d 18 #define G4 392
bhakti08 0:33ad8330e62d 19
bhakti08 0:33ad8330e62d 20 PwmOut buzzer(p26);
bhakti08 0:33ad8330e62d 21
bhakti08 0:33ad8330e62d 22
bhakti08 0:33ad8330e62d 23 float notes[] = {C4_1,C4,D4,C4,F4,E4,C4_1,C4,D4,C4,G4,F4,C4_1,C4,C5,A4,F4,E4,D4,B4b,B4b,A4,F4,G4,F4};
bhakti08 0:33ad8330e62d 24
bhakti08 0:33ad8330e62d 25
bhakti08 0:33ad8330e62d 26 float interval[] = {4, 4, 8, 8, 8, 10, 4, 4, 8, 8, 8, 10, 4, 4, 8, 8, 8, 8, 8, 4, 4, 8, 8, 8, 12};
bhakti08 0:33ad8330e62d 27
bhakti08 0:33ad8330e62d 28 int main() {
bhakti08 0:33ad8330e62d 29 while (1) {
bhakti08 0:33ad8330e62d 30 for (int i=0;i<=24;i++) {
bhakti08 0:33ad8330e62d 31 buzzer.period((1/notes[i])); // set PWM period
bhakti08 0:33ad8330e62d 32 buzzer=0.5; // set duty cycle
bhakti08 0:33ad8330e62d 33 wait(0.8*interval[i]/10); // hold for beat period
bhakti08 0:33ad8330e62d 34 }
bhakti08 0:33ad8330e62d 35 buzzer = 0;
bhakti08 0:33ad8330e62d 36 wait(5);
bhakti08 0:33ad8330e62d 37 }
bhakti08 0:33ad8330e62d 38 }
bhakti08 0:33ad8330e62d 39
bhakti08 0:33ad8330e62d 40
bhakti08 0:33ad8330e62d 41 /****************************************************************************************/
bhakti08 0:33ad8330e62d 42 /* TESTING */
bhakti08 0:33ad8330e62d 43 /****************************************************************************************/
bhakti08 0:33ad8330e62d 44
bhakti08 0:33ad8330e62d 45 /*1. Power up the mbed, load the program and press the reset button. The tone should play*/
bhakti08 0:33ad8330e62d 46 /* as long as the mbed is powered up. PASS*/
bhakti08 0:33ad8330e62d 47 /*****************************************************************************************/