Let's Make Robots!

Stringifying for Gareth

Here is my MP3 playing routine. It shows an int coming in, gettting converted to a string, and then assembled into a longer string which is then sent to the mp3 unit via serial. The only object you should need to make this work is "Numbers" with is sorta "Parallax standard".



PUB Playmp3 (number)    | b

   SetString( @mp3str, String("VPF"))    'this is the "play" command
   SetString( @mp3str3, String(".mp3"))
   if firsttime==true      ' this is the "start up" routine only done once
     waitcnt(clkfreq/10 + cnt)
     waitcnt(clkfreq/4  + cnt)
     mp3.str(string("VSV 10"))    'volume 50 is pretty low 0 is wicked loud

   b:=Numbers.ToStr(number,%1010)  'requested song number is now a string
   SetString(@mp3str2, (b))    'set the string as "we are going to work with it now"
   AddString ( @mp3str4,@mp3str2,@mp3str3) 'adds ".mp3" to song number (which is now a string)
   Addstring (@mp3str5,@mp3str,@mp3str4)  'adds "song.mp3" to "VPF" which is the play command
   'if 17 comes in we end up with "VPF17.mp3"
   mp3.str(@mp3str5)    'serial out to the mp3 player

PRI AddString( dstStrPtr, srcStrPtr1, srcStrPtr2 ) | len
  len := StrSize(srcStrPtr1)
  ByteMove(dstStrPtr, srcStrPtr1, len)
  ByteMove(dstStrPtr += len, srcStrPtr2, StrSize(srcStrPtr2))   '+1 for zero termination
PRI SetString( dstStrPtr, srcStrPtr )
  ByteMove(dstStrPtr, srcStrPtr, StrSize(srcStrPtr))  '+1 for zero termination

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Thanks for the tip Chris....... needed to give rest of the program a haircut...... however it works real fine.

Now my "Lassiter" can go forwards........

this is all i added to my sketch:

OBJ   num :"Numbers"


repeat  gr.colorwidth(0,8)   ' choose black and display old number to screen....effectively blanking out old value
            gr.text(-70,50,num.ToStr(xdisplay,%1010) )

             xdisplay:=  (wii.getx(@out,mode,blobs)-512)/4           'calculate x coord

            gr.colorwidth(1,8)   ' choose this time a colour and display in full glory the converted to string number
            gr.text(-70,50,num.ToStr(xdisplay,%1010) )