miniblip play notes with interrupts with variable volume

Dependencies:   mbed

Fork of blip_playnotes by Alberto Piganti

Committer:
pighixxx
Date:
Thu Nov 26 09:28:03 2015 +0000
Revision:
2:85d8ce475baa
Parent:
1:2e6ea42675c7
Child:
3:2af917fe09c3
miniblip play notes example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pighixxx 2:85d8ce475baa 1 // miniblip play notes with interrupts - Not tested with led matrix
pighixxx 2:85d8ce475baa 2 // For documentation see http://mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/
pighixxx 2:85d8ce475baa 3
4180_1 0:b2fdf3770282 4 #include "mbed.h"
4180_1 1:2e6ea42675c7 5 #include "SongPlayer.h"
4180_1 0:b2fdf3770282 6
4180_1 1:2e6ea42675c7 7 //Set up notes and durations for sample song to play
4180_1 1:2e6ea42675c7 8 // A 0.0 duration note at end terminates song play
4180_1 1:2e6ea42675c7 9 float note[18]= {1568.0,1396.9,1244.5,1244.5,1396.9,1568.0,1568.0,1568.0,1396.9,
4180_1 1:2e6ea42675c7 10 1244.5,1396.9,1568.0,1396.9,1244.5,1174.7,1244.5,1244.5, 0.0
4180_1 1:2e6ea42675c7 11 };
4180_1 1:2e6ea42675c7 12 float duration[18]= {0.48,0.24,0.72,0.48,0.24,0.48,0.24,0.24,0.24,
4180_1 1:2e6ea42675c7 13 0.24,0.24,0.24,0.24,0.48,0.24,0.48,0.48, 0.0
4180_1 1:2e6ea42675c7 14 };
4180_1 1:2e6ea42675c7 15
4180_1 0:b2fdf3770282 16 int main()
4180_1 0:b2fdf3770282 17 {
pighixxx 2:85d8ce475baa 18 // Buzzer pin
pighixxx 2:85d8ce475baa 19 SongPlayer mySpeaker(P0_8);
pighixxx 2:85d8ce475baa 20 // Start song and return once playing starts
4180_1 1:2e6ea42675c7 21 mySpeaker.PlaySong(note,duration);
4180_1 1:2e6ea42675c7 22 // loops forever while song continues to play to end using interrupts
4180_1 0:b2fdf3770282 23 while(1) {
4180_1 1:2e6ea42675c7 24 wait(.1);
4180_1 0:b2fdf3770282 25 }
4180_1 0:b2fdf3770282 26 }
4180_1 1:2e6ea42675c7 27