Canada
Asked — Edited

Rich. Your My Only Hope! ;-)

Rich,

I was wondering if you can help me out?

I need your programming wizardry.

I'm using a serial 40 MP3 module. It does not have a built in random feature.

Currently I just throw at it a script that it goes through the tracks one after the other.

If I stop that script to do something else then call it back it starts at the beginning. Not so random.

Could you help me out with some snazzy programming to give me a truely random feature?

The board uses a basic serial command such as:

sendserial(2.d0, 9600, 0x01)

0x01-0x40 are the tracks 1-40.

Anyway you could randomize this?


ARC Pro

Upgrade to ARC Pro

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

#1  

I'm not Rich, but have you tried using the GetRandom script?

Something like:


$Mp3Track = GetRandom(1,40)
SendSerial(2.d0, 9600, 0x$Mp3Track)

I ran this in a quick script and ARC accepted the code, but I don't have a serial device to verify against.

Canada
#2  

Awesome!

I'll give it a whirl.

I'll learn these variables and such sooner or later!

Thanks Again!

PRO
Synthiam
#3  

@Jeff, so close! you don't need the 0x

just simply

SendSerial(2.d0, 9600, $MP3Track)

:)

Canada
#4  

@Jeff, Code works great!

@DJ, If I remove the 0x it only plays like half of my audio files.

How does it know to prefix it with 0x if it's not there?

:Begin $Mp3Track = GetRandomUnique(1,14) SendSerial(d0, 9600, 0x$Mp3Track) Print("Now Playing Audio Track #" $Mp3Track) Sleep(5000) goto (Begin)

United Kingdom
#5  

It's good to see I am not your only hope after all:) Although flattery will get you everywhere...

United Kingdom
#6  

This may be where I post something that's wrong so take it with a pinch of salt but, if I understand correctly 0x00-0xFF are hex, 0-99 are decimal.

When you use 0x$MP3Track it limits it from 0x00 to 0x09, 0x10 to 0x19 etc. Missing out 0x0A-0x0F, 0x1A to 0x1F etc.

Therefore you are going to find you will miss tracks 10 to 15 (0x0A to 0x0F) 26 to 31 (0x1A to 0x1F) and so on.

You would need to convert the $mp3Track from a decimal to hex. I wont bother doing that since decimal works.

Although reading back through it I would have thought DJ's way would work and Jeffs miss some... Strange. Perhaps I have the above wrong? (Please someone let me know if I have).