![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
4180Lab2Part10
Fork of speaker_demo_PWM by
Diff: main.cpp
- Revision:
- 3:61d42134c1be
- Parent:
- 2:68eee0fb2026
diff -r 68eee0fb2026 -r 61d42134c1be main.cpp --- a/main.cpp Tue Oct 21 03:14:51 2014 +0000 +++ b/main.cpp Mon Feb 27 22:53:39 2017 +0000 @@ -6,15 +6,41 @@ // can also be used to play a song, if you have all of the notes and durations // for musical note frequencies see http://en.wikipedia.org/wiki/Piano_key_frequencies +float t = 2.5; //tempo controller + int main() { -// setup instance of new Speaker class, mySpeaker using pin 21 +// setup instance of new Speaker class, mySpeaker using pin 22 // the pin must be a PWM output pin - Speaker mySpeaker(p21); - // loops forever playing two notes on speaker + Speaker mySpeaker(p22); + //DigitalOut shutdown(p17); + // Ramblin Wreck while(1) { - mySpeaker.PlayNote(969.0,0.5,0.5); - mySpeaker.PlayNote(800.0,0.5,0.5); +//first verse using lower octave because the speaker has too much sauce + mySpeaker.PlayNote(783.991,1.0/t,0.1); // G + mySpeaker.PlayNote(698.456,0.5/t,0.1); //F + mySpeaker.PlayNote(622.254,0.9/t,0.1); //E flat + mySpeaker.PlayNote(0.0,0.1/t,0.0); //separation between the same notes + mySpeaker.PlayNote(622.254,0.4/t,0.1); //E flat + mySpeaker.PlayNote(0.0,0.1/t,0.0); + mySpeaker.PlayNote(622.254,1.0/t,0.1); //E flat + mySpeaker.PlayNote(698.456,0.5/t,0.1); //F + mySpeaker.PlayNote(783.991,0.9/t,0.1); // G + mySpeaker.PlayNote(0.0,0.1/t,0.0); + mySpeaker.PlayNote(783.991,0.4/t,0.1); // G + mySpeaker.PlayNote(0.0,0.1/t,0.0); + mySpeaker.PlayNote(783.991,0.5/t,0.1); // G + mySpeaker.PlayNote(698.456,0.5/t,0.1); //F + mySpeaker.PlayNote(622.254,0.5/t,0.1); //E flat + mySpeaker.PlayNote(698.456,0.4/t,0.1); //F + mySpeaker.PlayNote(0.0,0.1/t,0.0); + mySpeaker.PlayNote(698.456,0.4/t,0.1); //F + mySpeaker.PlayNote(0.0,0.1/t,0.0); + mySpeaker.PlayNote(698.456,0.5/t,0.1); //F + mySpeaker.PlayNote(622.254,1.0/t,0.1); //E flat + mySpeaker.PlayNote(587.330,0.5/t,0.1); //D + mySpeaker.PlayNote(622.254,2.5/t,0.1); //E flat + mySpeaker.PlayNote(0.0,0.5/t,0.0); //rest then repeat } }