Re: Coding for a "playlist"
Hi Tony,
Yeah, Lookup stores a list of constants at compile time, these can not be changed at a runtime. Instead you could use an array and a couple of index variables pointing into this array. Something like
Code:
PlayListMaximumLength CON 128
PlayList VAR BYTE[PlayListMaximumLength]
PlayPointer VAR BYTE
AddPointer VAR BYTE
Song VAR BYTE
AddPointer = 0 'Start adding songs from beginning of list
PlayPointer = 0 'Start playing songs from beginning of list
' Initilise playlist.
Song = 3 : Gosub AddSong
Song = 3 : Gosub AddSong
Song = 6 : Gosub AddSong
Song = 1 : Gosub AddSong
Song = 1 : Gosub AddSong
Song = 1 : Gosub AddSong
Song = 0 : Gosub Addsong ' Song=0 indicates end of list.
PlaySong:
While PlayList[PlayPointer] <> 0
' Do your thing here.
' Play the song.
' Check user inputs and GOSUB routines to add or manipulate the playlist.
PlayPointer = PlayPointer + 1 'Next song in list.
WEND
PlayPointer = 0 'Start over.
Goto PlaySong
AddSong:
PlayList[AddPointer] = Song
AddPointer = AddPointer + 1
If AddPointer = (PlayListMaximumLength - 1) THEN AddPointer = 0 'Wrap around and start over at the beginning of the list.
RETURN
Completely untested but illustrates one possible aproach. Another is to use the EEPROM (data/read/write) or even the program memory (readcode/writecode) to store and retreive the playlist, that way you can have it persistant.
/Henrik.
Re: Coding for a "playlist"
Hi Henrik,
Thank you for the response, but I'm looking to do it externally like a jukebox. Everything is programmed into the pic. I have some buttons that I'd like to scroll through the songs and select them with another button. So in essence, scroll through, see what I like, and when I find it, "yeah I want to hear this song" so I press the "select" button. Go onto the next song I like, press the "select" button again. When I'm done selecting my songs, it plays back my selection.
The code you showed, which I appreciate you taking the time, will play the order of songs entered during programming. I am trying to simulate a jukebox when I can create a playlist from external inputs. Your thoughts?
Thanks,
Tony
Re: Coding for a "playlist"
I know, and I think it's all there for you. But you need to implement the userinterface.
If you already have your buttons and everything used to scroll thru the list of available songs list you should be set. When you press "select" you set the Song-variable to whatever number the user has selected from the list and then GOSUB AddSong, the song is added to the list.
Code:
If UpButton = 1 Then Song = Song + 1 ' Point to next available song to chose from.
If DownButton = 1 Then Song = Song - 1 'Point to previous available song to chose from.
If SelectButton = 1 Then GOSUB AddSong 'Add selected song to list.
If RemoveButton = 1 then
AddPointer = AddPointer - 1 ' Take one step back in the list
PlayList[AddPointer] = 0 ' Remove last entry from list.
EndIf
If this is not what you mean I'm afraid I don't understand exactly what you're trying to do.
/Henrik.