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.cpp Source File

soundboard.cpp

00001 #include "soundboard.h"
00002 
00003 
00004 
00005 soundboard::soundboard(PinName resetPin, PinName clockPin, PinName dataPin, PinName busyPin) : _resetPin(resetPin), _clockPin(clockPin), _dataPin(dataPin), _busyPin(busyPin)
00006 {
00007     reset();
00008 }
00009 
00010 void soundboard::reset()
00011 {
00012     _clockPin = 0;
00013     _resetPin = 1;
00014     //Reset pulse.
00015     _resetPin = 0;
00016     wait_ms(5);
00017     _resetPin = 1;
00018     //Reset idle to start bit. 
00019     _clockPin = 1;
00020     wait_ms(300);
00021 }
00022 void soundboard::play(int trackNum)
00023 {
00024     sendCommand(trackNum);
00025     while(_busyPin==1);
00026 }
00027 void soundboard::playAsync(int trackNum )
00028 {
00029     sendCommand(trackNum);
00030 }
00031 void soundboard::stop(void)
00032 {
00033     sendCommand(STOP);
00034 }
00035 void soundboard::pause(void)
00036 {
00037     sendCommand(PLAY_PAUSE);
00038 }
00039 void soundboard::setVolume(int Volume)
00040 {
00041     sendCommand(Volume);
00042 }
00043 void soundboard::sendCommand(unsigned int cmd)
00044 {
00045     _clockPin = 0;
00046     wait_ms(2);
00047     for (unsigned int mask = 0x8000; mask>0; mask>>=1)
00048     {
00049         _clockPin=0;
00050         wait_us(50);
00051         if(cmd&mask)
00052         {
00053             _dataPin = 1;
00054         }
00055         else
00056         {
00057             _dataPin = 0;
00058         }
00059         wait_us(50);
00060         _clockPin=1;
00061         wait_us(100);
00062         if(mask>0x0001)
00063         {
00064             wait_ms(2);
00065         }
00066     }
00067     wait_ms(20);
00068 }
00069 void soundboard::playPerhapsAsync(int trackNum)
00070 {
00071     if(!_busyPin)
00072     {
00073         playAsync(trackNum);
00074     }
00075 }