Laura Delaney / Mbed 2 deprecated Ldelaney17_frdm_Final_Project

Dependencies:   DmTouch_UniGraphic UniGraphic-forLdelaney17FinalProject mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Song.cpp Source File

Song.cpp

00001 #include "Song.h"
00002 
00003 void mute(){
00004     note_duration.detach();
00005     myBuzzer = 0;    
00006 }
00007 
00008 void Song::play(){
00009         if (place_in_song < song_length){
00010             set_note(place_in_song);
00011             note_duration.attach(this, &Song::play, beat_length*beats[place_in_song]);
00012             place_in_song++;
00013         }
00014         else{
00015             mute();
00016             place_in_song = 0;
00017         }
00018     }
00019     
00020     void Song::set_note(int index){
00021         myBuzzer.period(1/(2*freqs[index]));
00022         myBuzzer = 0.5;
00023     }
00024     
00025     void Song::set_tempo(int tempo){
00026         beat_length = 60.0/tempo;
00027     }