Lab2Part14

Dependencies:   mbed

Committer:
TCNoodleshop
Date:
Mon Oct 07 02:40:31 2019 +0000
Revision:
0:59e9c82b3e5f
Lab2Part14;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TCNoodleshop 0:59e9c82b3e5f 1 #include "mbed.h"
TCNoodleshop 0:59e9c82b3e5f 2 #include "SongPlayer.h"
TCNoodleshop 0:59e9c82b3e5f 3
TCNoodleshop 0:59e9c82b3e5f 4 // Song test program - plays a song using PWM and timer interrupts
TCNoodleshop 0:59e9c82b3e5f 5 // for documentation see http://mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/
TCNoodleshop 0:59e9c82b3e5f 6 // can be used to play a song, if you have the notes and durations
TCNoodleshop 0:59e9c82b3e5f 7 // for musical note frequencies see http://en.wikipedia.org/wiki/Piano_key_frequencies
TCNoodleshop 0:59e9c82b3e5f 8
TCNoodleshop 0:59e9c82b3e5f 9 //Set up notes and durations for sample song to play
TCNoodleshop 0:59e9c82b3e5f 10 // A 0.0 duration note at end terminates song play
TCNoodleshop 0:59e9c82b3e5f 11 float note[18]= {1568.0,1396.9,1244.5,1244.5,1396.9,1568.0,1568.0,1568.0,1396.9,
TCNoodleshop 0:59e9c82b3e5f 12 1244.5,1396.9,1568.0,1396.9,1244.5,1174.7,1244.5,1244.5, 0.0
TCNoodleshop 0:59e9c82b3e5f 13 };
TCNoodleshop 0:59e9c82b3e5f 14 float duration[18]= {0.48,0.24,0.72,0.48,0.24,0.48,0.24,0.24,0.24,
TCNoodleshop 0:59e9c82b3e5f 15 0.24,0.24,0.24,0.24,0.48,0.24,0.48,0.48, 0.0
TCNoodleshop 0:59e9c82b3e5f 16 };
TCNoodleshop 0:59e9c82b3e5f 17
TCNoodleshop 0:59e9c82b3e5f 18 DigitalOut led1(LED1);
TCNoodleshop 0:59e9c82b3e5f 19 int main()
TCNoodleshop 0:59e9c82b3e5f 20 {
TCNoodleshop 0:59e9c82b3e5f 21 // setup instance of new SongPlayer class, mySpeaker using pin 26
TCNoodleshop 0:59e9c82b3e5f 22 // the pin must be a PWM output pin
TCNoodleshop 0:59e9c82b3e5f 23 SongPlayer mySpeaker(p26);
TCNoodleshop 0:59e9c82b3e5f 24 // Start song and return once playing starts
TCNoodleshop 0:59e9c82b3e5f 25 mySpeaker.PlaySong(note,duration);
TCNoodleshop 0:59e9c82b3e5f 26 // loops forever while song continues to play to end using interrupts
TCNoodleshop 0:59e9c82b3e5f 27 while(1) {
TCNoodleshop 0:59e9c82b3e5f 28 led1 = !led1;
TCNoodleshop 0:59e9c82b3e5f 29 wait(.1);
TCNoodleshop 0:59e9c82b3e5f 30 }
TCNoodleshop 0:59e9c82b3e5f 31 }
TCNoodleshop 0:59e9c82b3e5f 32