JakeSoft:
Ok, guys. Here is another drop of the Universal Saber library. The major addition is: Sound! I finally added sound support. And let me tell you, this one didn't come easy. I added an example of how to implement a sound-handling class by creating a saber sound player for the WT588D. I'm still working on multi-font support, but the interface will at least support one sound font plus menu sounds. This is likely enough for simple projects.
- Added sound support!
WT588DSoundPlayer: A sabers sound player for the WT588D.
You have to parameterize it to tell it how many sound of each type (swing, clash, power-up, etc) you have by populating a data structure. This is an alternative to a bunch of #define or const int statements that have typically been used. It puts it all in one convenient place. These are all things you would have to define anyway, the constructor just forces you to do it up front.
So for example, if you had in your WT588D equations (play lists) programmed like this:
0x00 = Power Up
0x01 = Hum
0x02 = Swing
0x03 = Clash 1
0x04 = Clash 2
0x05 = Power Down
You'd parameterize as in the following example sketch:
#include<USaber.h>
//The data structure that describes your sound layout
WT588DSoundMap gSoundMap;
//Pointer to the actual sound player
ASoundPlayer* gpSaberSound;
//The I/O pin for one-line serial comms
#define WT588D_SDA 13
void setup()
{
//Sound font features
gSoundMap.Features.PowerUpSoundsPerFont = 1;
gSoundMap.Features.HumSoundsPerFont = 1;
gSoundMap.Features.SwingSoundsPerFont = 1;
gSoundMap.Features.ClashSoundsPerFont = 2; //0x03 and 0x04 are clash sounds
gSoundMap.Features.PowerDownSoundsPerFont = 1;
//Base address offset for all sounds (typically zero)
gSoundMap.Locations.BaseAddr = 0;
//Sound locations on the module
gSoundMap.Locations.PowerupBase = 0;
gSoundMap.Locations.HumBase = 1;
gSoundMap.Locations.SwingBase = 2;
gSoundMap.Locations.ClashBase = 3; //0x03 and 0x04 are clash sounds
gSoundMap.Locations.PowerdownBase = 5;
//Now create the player
gpSaberSound = new WT588DSoundPlayer(WT588D_SDA, &gSoundMap);
//And intialize it
gpSaberSound->Init();
}
void loop()
{
//code code code...
//Get to a place where you want play a power up sound and...
gpSaberSound->PlaySound(eePowerUpSnd, 0); //Play the 0th (the first) power-up sound
//blah blah blah...
//Get to a place where you want to play a random clash sound...
gpSaberSound->PlayRandomSound(eeClashSnd);
}
2. Fixed a bug in **SimpleMotionManager** that would sometimes allow double-trigger on clash events.
Whew, I need a break. I hope you all enjoy. MTFBWY.
EXCELENT JAKESOFT ...... !!!!!!
In the future, I will try this library.