Go Down

Topic: Arduino Lightsaber (Read 414654 times) previous topic - next topic

splinter182

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.

1. 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:
Code: [Select]

#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.
Awesome work JakeSoft!

I think i'm gonna have to do a LSOS and USaber hybrid.

Soulbp

There is a place just down the street from me that makes PCBs, they also populate boards etc,.. After I get everything working I was planing on going-over to them to see what they can do. They maybe able give me some direction on both the flash and single USB for all shortage. I'd also like ubs recharge for the batteries if it can all be one port. That kills alot of birds with one stone.

JakeSoft

There is a place just down the street from me that makes PCBs, they also populate boards etc,.. After I get everything working I was planing on going-over to them to see what they can do. They maybe able give me some direction on both the flash and single USB for all shortage. I'd also like ubs recharge for the batteries if it can all be one port. That kills alot of birds with one stone.
Lucky you! That'll make shipping a non-issue for you. Are you state side? So far, the only folks who have shown enough ambition to build PCBs are in Europe. Great for them, but the shipping is painful for us Yankees.

Soulbp

Yes, im state side. Once I have a working model and talk to them I can let you know what they quote and what they say.

Protonerd

Lucky you! That'll make shipping a non-issue for you. Are you state side? So far, the only folks who have shown enough ambition to build PCBs are in Europe. Great for them, but the shipping is painful for us Yankees.
No need to shed Yankee tears :) I talked to the local post clerk, it seems an insured, bubble foil envelope costs about 10$, actually no matter where I send it (US the same as when I send to a neighboring country), non-insured is ~4$.

Protonerd

Look what I've found:
http://www.ebay.de/itm/4-Stueck-USB-Rechargeable-4200mAh-3-7V-BRC-18650-Batterie-Battery-Li-ion-AKKU-UK-/272065940619?_trksid=p2141725.m3641.l6368

A 3.7V type 18650 battery with in-built USB recharger...? How cool is that? It seems it's only slightly longer (67mm instead of 65) but has a great capacity. Maybe such a battery can be tweaked to connect to the USB of the board and have it charged while connected.

JakeSoft

No need to shed Yankee tears :) I talked to the local post clerk, it seems an insured, bubble foil envelope costs about 10$, actually no matter where I send it (US the same as when I send to a neighboring country), non-insured is ~4$.
Well, that's good news. For comparison, domestic uninsured padded envelope from the United States Postal Service is ~2 USD according to my local post office. It goes up from there depending on how much insurance you add.

Canobi

Hi guys

Started populating the boards only to find the provided SOT-23-5 footprint (used for the 3v3 regulator) is way off scale so had to make my own and mod the layout artwork. Major bummer as finding the couple hrs straight needed to make them was not easy. Got time off next week so I'll see about re doing them then.

I'm also having trouble with converted audio as well. For some reason the WT software won't accept anything above 8Khz, anyone else had this problem?

splinter182

Look what I've found:
http://www.ebay.de/itm/4-Stueck-USB-Rechargeable-4200mAh-3-7V-BRC-18650-Batterie-Battery-Li-ion-AKKU-UK-/272065940619?_trksid=p2141725.m3641.l6368

A 3.7V type 18650 battery with in-built USB recharger...? How cool is that? It seems it's only slightly longer (67mm instead of 65) but has a great capacity. Maybe such a battery can be tweaked to connect to the USB of the board and have it charged while connected.
I would not suggest those, the highest 18650 capacity is 3400mah from phillip NCR cells that are pretty expensive. Those are probably some 14500 cells inside a 18650 body with a usb lipo charger, probably a 900mah actuall capacity.

I'm also having trouble with converted audio as well. For some reason the WT software won't accept anything above 8Khz, anyone else had this problem?
thats weird, i just open my wavs in audacity, manually change the project rate to 22000 hz and save the new wavs

Canobi

thats weird, i just open my wavs in audacity, manually change the project rate to 22000 hz and save the new wavs
I'm doing exactly that using three audio software packages, audacity (the only free one I've used), acid pro 6 and soundforge 7 but no joy :/

Might do a wt software reinstall and see if that helps.

JakeSoft

I'm doing exactly that using three audio software packages, audacity (the only free one I've used), acid pro 6 and soundforge 7 but no joy :/

Might do a wt software reinstall and see if that helps.
Is the WT software rejecting your sound files when you attempt to import?

Make sure you actually type "22000" in the project rate menu. If you use the pull down menu without typing, then it will go to 22050, which won't work.


Canobi

Is the WT software rejecting your sound files when you attempt to import?

Make sure you actually type "22000" in the project rate menu. If you use the pull down menu without typing, then it will go to 22050, which won't work.
Tried that, same story :(

JakeSoft

Tried that, same story :(
Hmm. That's weird. I've converted probably hundreds of files that way at 10K, 20K, and 22K Hz and it's always worked. If you continue to have problems, you could send me your sound files and I could possibly build the binary for you.

Canobi

Thanks Jake, I'll bare that in mind.

I'm sure it's something stupidly simple going on, not heard anyone else complain about sampling frequency problems.

Canobi

Found out what the issue was.

The sound files I was trying to convert were mono so I switched to a set of stereo files and it worked a treat.

Go Up