' ========================================================================= ' ' File....... uMP3-Music-Player.BS1 ' Purpose.... Random song player ' Author..... Jon Williams -- Parallax, Inc. ' E-mail..... jwilliams@parallax.com ' Started.... 17 OCT 2005 ' Updated.... 24 OCT 2005 ' ' {$STAMP BS1} ' {$PBASIC 1.0} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' This program requires uMP3 firmware version 110.11. ' -- set baud to 2400 (ST D) ' -- set prompt delay to 5 milliseconds (ST R) ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- SYMBOL Trigger = PIN6 SYMBOL TX = 5 SYMBOL RX = 4 ' -----[ Constants ]------------------------------------------------------- SYMBOL Yes = 0 SYMBOL No = 1 SYMBOL Baud = OT2400 SYMBOL Mp3Count = 6 ' files on uMP3 ' -----[ Variables ]------------------------------------------------------- SYMBOL markers = B0 ' song has played SYMBOL tag = B1 SYMBOL char = B2 ' character to/from uMP3 SYMBOL theMP3 = B3 ' file# to play SYMBOL eePntr = B4 ' eeprom pointer SYMBOL lottery = W3 ' random number ' -----[ EEPROM Data ]----------------------------------------------------- BitSet: EEPROM ($01, $02, $04, $08, $10, $20, $40, $80) ' Song list contains name of file only, and must be followed by zero MP3s: EEPROM ("Frosty the Snowman", 0) EEPROM ("Jingle Bells", 0) EEPROM ("Joy to the World", 0) EEPROM ("Let It Snow", 0) EEPROM ("Little Drummer Boy", 0) EEPROM ("Silent Night", 0) ' -----[ Initialization ]-------------------------------------------------- Reset: PAUSE 2000 ' let uMP3 start Prod_uMP3: SEROUT TX, Baud, (13) ' send CR SERIN RX, Baud, char ' get response IF char <> ">" THEN Prod_uMP3 ' wait for ">" lottery = 1225 ' seed random value markers = %11000000 ' reset markers ' -----[ Program Code ]---------------------------------------------------- Main: RANDOM lottery ' tumble random value IF Trigger = No THEN Main ' wait for trigger theMP3 = lottery // Mp3Count ' create file#, 0..N READ theMP3, tag ' read tag bit char = markers & tag ' check markers fo played IF char > 0 THEN Main ' if played, try again markers = markers | tag ' mark played GOSUB Play_MP3 ' play it IF markers < %11111111 THEN Main ' all played? markers = %11000000 ' yes, reset markers GOTO Main ' -----[ Subroutines ]----------------------------------------------------- ' Put file # to play in "theMP3" ' -- "theMP3" will be destroyed by subroutine Play_MP3: eePntr = 8 ' reset pointer IF theMP3 = 0 THEN Send_Cmd ' at position, play it Fast_Fwd: ' move to selected title READ eePntr, char ' retrieve a character eePntr = eePntr + 1 ' advance pointer IF char <> 0 THEN Fast_Fwd ' if not 0, try again theMP3 = theMP3 - 1 ' else, decrement file# IF theMP3 > 0 THEN Fast_Fwd ' if > 0, not at titel yet Send_Cmd: SEROUT TX, Baud, ("PC F /") ' start play command Send_Name: ' send file title READ eePntr, char eePntr = eePntr + 1 IF char = 0 THEN Finish_Cmd SEROUT TX, Baud, (char) GOTO Send_Name Finish_Cmd: SEROUT TX, Baud, (".MP3", 13) ' send extention + CR Wait_For_Stop: ' let song finish PAUSE 100 SEROUT TX, Baud, ("PC Z", 13) SERIN RX, Baud, char IF char <> "S" THEN Wait_For_Stop RETURN