![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Speakertest
Dependencies: SDFileSystem mbed wave_player
Revision 0:7e6d1d7b2ae0, committed 2016-01-25
- Comitter:
- Nikolas
- Date:
- Mon Jan 25 13:14:30 2016 +0000
- Commit message:
- Speakertest program;
Changed in this revision
diff -r 000000000000 -r 7e6d1d7b2ae0 SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Mon Jan 25 13:14:30 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/sparkfun/code/SDFileSystem/#7b35d1709458
diff -r 000000000000 -r 7e6d1d7b2ae0 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Jan 25 13:14:30 2016 +0000 @@ -0,0 +1,65 @@ +// Soundboard that plays 1 of 4 .wav files stored on the SD card based on 1 of +// 4 buttons pressed + +#include "mbed.h" +#include "wave_player.h" +#include "SDFileSystem.h" + +// .wav files to play +const char *filenames[1] = { "/sd/Sandstorm.wav" + }; + +// Define button +DigitalIn button_1(p27); + +// USB serial (tx, rx) +Serial pc(USBTX, USBRX); + +// SD card +SDFileSystem sd(p11, p12, p13, p24, "sd"); + +// Audio out (DAC) +AnalogOut DACout(p18); +wave_player waver(&DACout); + +// Play a .wav file +int playSound(int file_num) { + + FILE *file; + + // Open sound file for reading + file = fopen(filenames[file_num], "r"); + if ( file == NULL ) { + error("ERROR: Could not open file for reading!\n"); + return -1; + } + + // Play the sound file + pc.printf("Playing sound clip %i\r\n", (file_num + 1)); + waver.play(file); + + // Reset to beginning of file and close it + fseek(file, 0, SEEK_SET); + fclose(file); + + return 0; +} + +int main() { + + // Use internal pull-up resistors + button_1.mode(PullUp); + + pc.printf("\r\nHardware Soundboard\r\n"); + + while(1) { + + // Figure out which button was pressed and play that file + if ( button_1 == 0 ) { + playSound(0); + } + + // Wait 10ms before sampling the buttons again + wait(0.01); + } +}
diff -r 000000000000 -r 7e6d1d7b2ae0 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Jan 25 13:14:30 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96 \ No newline at end of file
diff -r 000000000000 -r 7e6d1d7b2ae0 wave_player.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wave_player.lib Mon Jan 25 13:14:30 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/sparkfun/code/wave_player/#acc3e18e77ad