Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of flash_audio_player_8bit by
Revision 2:9d7fa7666ee4, committed 2017-10-22
- Comitter:
- 4180_1
- Date:
- Sun Oct 22 16:50:32 2017 +0000
- Parent:
- 1:bd7bef7df00b
- Commit message:
- ver 1.0
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r bd7bef7df00b -r 9d7fa7666ee4 main.cpp --- a/main.cpp Sun Oct 22 16:12:03 2017 +0000 +++ b/main.cpp Sun Oct 22 16:50:32 2017 +0000 @@ -1,9 +1,9 @@ #include "mbed.h" -AnalogOut speaker(p18); +PwmOut speaker(p26); Ticker sampletick; DigitalOut myled(LED1); //Plays Audio Clip using Array in Flash -//8-bit audio samples used +//8-bit audio samples used on PWM pin //setup const array in flash with audio values //from free wav file conversion tool at //http://ccgi.cjseymour.plus.com/wavtocode/wavtocode.htm @@ -14,19 +14,11 @@ //get and set the frequency from wav conversion tool GUI int i=0; -union short_or_char { - short s; - char c[2]; -}; - -union short_or_char sample; - - //interrupt routine to play next audio sample from array in flash void audio_sample () { - sample.c[1] = sound_data[i]; - speaker.write_u16(sample.s); + + speaker = sound_data[i]/255.0;//scale to 0.0 to 1.0 for PWM i++; if (i>= NUM_ELEMENTS) { i = 0; @@ -36,7 +28,7 @@ } int main() { - sample.c[0] = 0; //setup fast byte to short conversion using union + speaker.period(1.0/250000.0); //PWM freq >10X audio sample rate while(1) { myled = 1; //use a ticker to play send next audio sample value to D/A