EJ Teb / WTV020SD_Sound_Breakout_Library

Dependents:   Nucleo_SoundBoardTest Robot Progetto_finale Progetto_finale_noLCD ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers soundboard.h Source File

soundboard.h

00001 #ifndef MBED_SOUNDBOARD_H
00002 #define MBED_SOUNDBOARD_H
00003 
00004 #include "mbed.h"
00005 
00006 #define MUTE VOL_0
00007 #define VOL_0 0xFFF0
00008 #define VOL_1 0xFFF1
00009 #define VOL_2 0xFFF2
00010 #define VOL_3 0xFFF3
00011 #define VOL_4 0xFFF4
00012 #define VOL_5 0xFFF5
00013 #define VOL_6 0xFFF6
00014 #define VOL_7 0xFFF7
00015 #define PLAY_PAUSE 0xFFFE
00016 #define STOP 0xFFFF
00017 /**
00018 * soundboard class
00019 * Used to control the WTV020SD board from sparkfun
00020 * Find out more at https://www.sparkfun.com/products/11125
00021 * Example:
00022 @code
00023 #include "mbed.h"
00024 #include "soundboard.h"
00025 int main(void)
00026 {
00027    //initialise the soundboard
00028    soundboard mySoundBoard(D1, D2, D3, D4);
00029    //play track 0
00030    mySoundBoard.play(0);
00031    //play track 1
00032    mySoundBoard.playAsync(1);
00033    //set the volume as 3
00034    mySoundBoard.setVolume(VOL_3);
00035    wait(.5);
00036    //set the volume as 7 (max)
00037    mySoundBoard.setVolume(VOL_7);
00038    wait(.5);
00039    //mute the playback, but the playback will continue
00040    mySoundBoard.setVolume(MUTE);
00041    wait(.5);
00042    //pause playback
00043    mySoundBoard.pause();
00044    wait(.5);
00045    //continue playback
00046    mySoundBoard.pause();
00047    wait(.5);
00048    //reset the soundboard.
00049    mySoundBoard.reset();
00050    while(1);
00051 }
00052 @endcode
00053 */
00054 class soundboard
00055 {
00056 public:
00057     /** Creates the soundboard class with the specified reset pin, clock pin, data pin and busy pin*/
00058     soundboard(PinName resetPin, PinName clockPin, PinName dataPin, PinName busyPin);
00059     /** resets the soundboard*/
00060     void reset(void);
00061     /** plays the given track, Code will be blocked until the track has finished playing
00062     @param <tracknum> the number of the track which should be played*/
00063     void play(int);
00064     /** plays the given track, Code will continue running while the track is playing
00065     @param <tracknum> the number of the track which should be played*/
00066     void playAsync(int);
00067     /** stops play back of the current track, only works if the track was played using playAsync*/
00068     void stop(void);
00069     /** pauses the currently playing track, or plays the currently paused track, only works if the track was played using playAsync*/
00070     void pause(void);
00071     /** sets the volume of the playback. Use VOL_0 through to VOL_7*/
00072     void setVolume(int);
00073     /**plays if something else is not playing**/
00074     void playPerhapsAsync(int);
00075 private:
00076     void sendCommand(unsigned int);
00077     DigitalOut _resetPin;
00078     DigitalOut _clockPin;
00079     DigitalOut _dataPin;
00080     DigitalIn _busyPin;
00081     
00082 };
00083 
00084 #endif