A library for the WTV020SD sound breakout board
Dependents: Nucleo_SoundBoardTest Robot Progetto_finale Progetto_finale_noLCD ... more
soundboard.h@2:d6b7b90b4387, 2014-11-24 (annotated)
- Committer:
- ejteb
- Date:
- Mon Nov 24 20:09:32 2014 +0000
- Revision:
- 2:d6b7b90b4387
- Parent:
- 1:b24351bba700
With playPerhapsAsync(int)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ejteb | 0:03560ce39755 | 1 | #ifndef MBED_SOUNDBOARD_H |
ejteb | 0:03560ce39755 | 2 | #define MBED_SOUNDBOARD_H |
ejteb | 0:03560ce39755 | 3 | |
ejteb | 0:03560ce39755 | 4 | #include "mbed.h" |
ejteb | 0:03560ce39755 | 5 | |
ejteb | 0:03560ce39755 | 6 | #define MUTE VOL_0 |
ejteb | 0:03560ce39755 | 7 | #define VOL_0 0xFFF0 |
ejteb | 0:03560ce39755 | 8 | #define VOL_1 0xFFF1 |
ejteb | 0:03560ce39755 | 9 | #define VOL_2 0xFFF2 |
ejteb | 0:03560ce39755 | 10 | #define VOL_3 0xFFF3 |
ejteb | 0:03560ce39755 | 11 | #define VOL_4 0xFFF4 |
ejteb | 0:03560ce39755 | 12 | #define VOL_5 0xFFF5 |
ejteb | 0:03560ce39755 | 13 | #define VOL_6 0xFFF6 |
ejteb | 0:03560ce39755 | 14 | #define VOL_7 0xFFF7 |
ejteb | 0:03560ce39755 | 15 | #define PLAY_PAUSE 0xFFFE |
ejteb | 0:03560ce39755 | 16 | #define STOP 0xFFFF |
ejteb | 0:03560ce39755 | 17 | /** |
ejteb | 0:03560ce39755 | 18 | * soundboard class |
ejteb | 0:03560ce39755 | 19 | * Used to control the WTV020SD board from sparkfun |
ejteb | 0:03560ce39755 | 20 | * Find out more at https://www.sparkfun.com/products/11125 |
ejteb | 0:03560ce39755 | 21 | * Example: |
ejteb | 0:03560ce39755 | 22 | @code |
ejteb | 0:03560ce39755 | 23 | #include "mbed.h" |
ejteb | 0:03560ce39755 | 24 | #include "soundboard.h" |
ejteb | 0:03560ce39755 | 25 | int main(void) |
ejteb | 0:03560ce39755 | 26 | { |
ejteb | 1:b24351bba700 | 27 | //initialise the soundboard |
ejteb | 1:b24351bba700 | 28 | soundboard mySoundBoard(D1, D2, D3, D4); |
ejteb | 1:b24351bba700 | 29 | //play track 0 |
ejteb | 1:b24351bba700 | 30 | mySoundBoard.play(0); |
ejteb | 1:b24351bba700 | 31 | //play track 1 |
ejteb | 1:b24351bba700 | 32 | mySoundBoard.playAsync(1); |
ejteb | 1:b24351bba700 | 33 | //set the volume as 3 |
ejteb | 1:b24351bba700 | 34 | mySoundBoard.setVolume(VOL_3); |
ejteb | 1:b24351bba700 | 35 | wait(.5); |
ejteb | 1:b24351bba700 | 36 | //set the volume as 7 (max) |
ejteb | 1:b24351bba700 | 37 | mySoundBoard.setVolume(VOL_7); |
ejteb | 1:b24351bba700 | 38 | wait(.5); |
ejteb | 1:b24351bba700 | 39 | //mute the playback, but the playback will continue |
ejteb | 1:b24351bba700 | 40 | mySoundBoard.setVolume(MUTE); |
ejteb | 1:b24351bba700 | 41 | wait(.5); |
ejteb | 1:b24351bba700 | 42 | //pause playback |
ejteb | 1:b24351bba700 | 43 | mySoundBoard.pause(); |
ejteb | 1:b24351bba700 | 44 | wait(.5); |
ejteb | 1:b24351bba700 | 45 | //continue playback |
ejteb | 1:b24351bba700 | 46 | mySoundBoard.pause(); |
ejteb | 1:b24351bba700 | 47 | wait(.5); |
ejteb | 1:b24351bba700 | 48 | //reset the soundboard. |
ejteb | 1:b24351bba700 | 49 | mySoundBoard.reset(); |
ejteb | 1:b24351bba700 | 50 | while(1); |
ejteb | 0:03560ce39755 | 51 | } |
ejteb | 0:03560ce39755 | 52 | @endcode |
ejteb | 0:03560ce39755 | 53 | */ |
ejteb | 0:03560ce39755 | 54 | class soundboard |
ejteb | 0:03560ce39755 | 55 | { |
ejteb | 0:03560ce39755 | 56 | public: |
ejteb | 0:03560ce39755 | 57 | /** Creates the soundboard class with the specified reset pin, clock pin, data pin and busy pin*/ |
ejteb | 0:03560ce39755 | 58 | soundboard(PinName resetPin, PinName clockPin, PinName dataPin, PinName busyPin); |
ejteb | 0:03560ce39755 | 59 | /** resets the soundboard*/ |
ejteb | 0:03560ce39755 | 60 | void reset(void); |
ejteb | 0:03560ce39755 | 61 | /** plays the given track, Code will be blocked until the track has finished playing |
ejteb | 0:03560ce39755 | 62 | @param <tracknum> the number of the track which should be played*/ |
ejteb | 0:03560ce39755 | 63 | void play(int); |
ejteb | 0:03560ce39755 | 64 | /** plays the given track, Code will continue running while the track is playing |
ejteb | 0:03560ce39755 | 65 | @param <tracknum> the number of the track which should be played*/ |
ejteb | 0:03560ce39755 | 66 | void playAsync(int); |
ejteb | 0:03560ce39755 | 67 | /** stops play back of the current track, only works if the track was played using playAsync*/ |
ejteb | 0:03560ce39755 | 68 | void stop(void); |
ejteb | 0:03560ce39755 | 69 | /** pauses the currently playing track, or plays the currently paused track, only works if the track was played using playAsync*/ |
ejteb | 0:03560ce39755 | 70 | void pause(void); |
ejteb | 0:03560ce39755 | 71 | /** sets the volume of the playback. Use VOL_0 through to VOL_7*/ |
ejteb | 0:03560ce39755 | 72 | void setVolume(int); |
ejteb | 2:d6b7b90b4387 | 73 | /**plays if something else is not playing**/ |
ejteb | 2:d6b7b90b4387 | 74 | void playPerhapsAsync(int); |
ejteb | 0:03560ce39755 | 75 | private: |
ejteb | 0:03560ce39755 | 76 | void sendCommand(unsigned int); |
ejteb | 0:03560ce39755 | 77 | DigitalOut _resetPin; |
ejteb | 0:03560ce39755 | 78 | DigitalOut _clockPin; |
ejteb | 0:03560ce39755 | 79 | DigitalOut _dataPin; |
ejteb | 0:03560ce39755 | 80 | DigitalIn _busyPin; |
ejteb | 0:03560ce39755 | 81 | |
ejteb | 0:03560ce39755 | 82 | }; |
ejteb | 0:03560ce39755 | 83 | |
ejteb | 0:03560ce39755 | 84 | #endif |