And now that i've got passed the hurdle i've adapted the code again to include a pause button instead of the green glowing play button, both bitmaps included in case you wish to use either. save bitmaps to root of uSD along with wav files
Artist and album title can be changed to whatever is needed.
Read the readme txt for further info
The play button changes to a pause button but the code needs to be written to toggle the bitmaps back and forth and also to pause the wavs
I think that this will involve putting the touchscreen code in another cog so a repeat loop can run indefinitely and pass presses to the main program this will also make it easier to have toggles like the backlight on and off
I checked the current draw with the player and all leds running and it came out to approx 155ma running at 4.5 V on battery power, is this ok for an unpowered USB port? Noticed the usb plug that goes into the laptop gets warm.
One question does the screen allow support for using an alpha channel on the bitmaps as it would save having to change the bitmaps backgrounds whenever the main background is changed.
The screen does not have alpha channel support. You could probably add this with code, but it would be slow...
Using square buttons would probably solve this problem.
Another way might be to use 4 or 8 bit bitmaps with the background color forced to be some constant color number. Then, you could just change the palette so the image background color matched the screen background.
All a lot of work compared to using rectangular button areas...
Its no problem to edit the controls with an editor using fill so not an issue
an editor like zoner photo studio allows you to enter the RGB values that you chose for the background to the bitmap fill
I'm trying to understand from the code how the touchscreen area for the play button is worked out. so that could be applied to the different controls
Is this done with a square over the button or does the code work out the shape and size of the button?
I figured it out by drawing a white rectangle on top of the screen and playing with the coordinates until it was where I wanted it...
(Probably not the best way). You can probably still find, commented out, the line that draws the rectangle.
I wonder if coordinates that use a centre and a formula for diameter could also work out the area for circular objects like the play/pause button? Probably easier with the rectangle though
I'll look for the code and experiment a bit
Found the code but why are there dashes between the last three numbers 240-51-20 rather than commas are those numbers being subtracted from 240 and which number corresponds to the correct buttonPlay array variable?
sorry to keep asking questions but with this knowledge I can look at creating touchscreen areas for the other controls in advance of the code for actually doing something with the press.
That's if you don't mind me doing so
bmp(50,240-51-20,string("PlayBG.bmp")) 'Play button with light green background
'lcd.DrawRectangle(lcd#rgb_white,buttonPlay[0],buttonPlay[2],buttonPlay[1],buttonPlay[3]) 'see where button is
no problem. The dashes are minus signs... I started with 240 and the tried moving it up 51 pixels and then moved it up another 20 pixels..
Was being lazy...
Thanks for that info it's enabled me to work out the coords of the stop button(to the pixel) , some of the coords are negative numbers is that ok?
buttonStop byte -171,-181,189,199,1 'coords of stop button
what does the 1 at the end do I tried increasing this when drawing the rectangle as I presumed it was thickness of the line but changing it did nothing?
That last number, "1", is what the "GetButton" function will return when button is pushed.
The other numbers are x and y coordinates of the button on the screen. X should be between 0 and 319 and Y should
be between 0 and 239. negative numbers won't give an error, but shouldn't be used...
Ah Clever stuff, you've certainly worked out the structure of this code in advance!
I can use 2 to denote the stop button which I am in the process of designing for pressed or set
I'll redo the code to get rid of the neg numbers should be a doddle now to map the Next track and previous track buttons too
The action code will take me a time to work out unless you are already on the case with that?
What about the idea about the touchscreen and relevant code in a different cog and perhaps in it's own object, would that be necessary to allow touches whilst the wav plays?
Edit: New coordinate for stopbutton without neg numbers:
buttonStop byte 75,85,189,199,2 'coords of stop button 2=stopbutton
Thanks Rayman for those snippets about the code it's really helping me to understand it
Like in the Draw rectangle code the way you can just name the colour rather than having to type in the RGB values
Is there a table of what colours you can use that way with the screen? Is that the eight colours mentioned in the paint code?
Worked out the problem with sorting the tracks, load them one at a time in order rather than copying them altogether to the uSD
New designed Stop Button(Thank heaven for the clone button feature in zoner photo studio, used to get gradiant for curve effect from adjacent button)
Going to have to make several versions for diffent scenarios such as play button stop unset play set to pause and stop button either set or not etc etc
or will I be able to draw a bitmap at a location like you can draw a rectangle? then it would just be a case of saving button bitmaps rather than the whole control bar for each scenario.
, will have to change coords in the code before posting for it tomorrow too tired to do that tonight:
Have created a WavPlayerLoopControls.spin to show the sequence of button pushes from the play button to the pause button after 5 secs and then 5 secs later the stop button depresses which very quickly returns back to the start. I put this in a continuous loop in order to show what the controls look like in the intended sequence of use
If you get a chance please have a look as I'd like comments about whether you think it looks ok or not., the three bitmaps are included in the archive and you need to click the play button to start the sequence.
Bitmaps for next and prev buttons to follow later
I'll work on makeing the player and touchscreen interface better for this application...
Thanks Rayman I appreciate that
Another question, does the bitmap draw wipe the entire screen ie if I drew a bitmap for a frame and then drew a bitmap for the controls would the controls bitmap erase the entire screen or only the portion of screen below where it's placed? The answer will decide which way to go in designing the Wavplayer screen
Noticed another problem when trying to display a 320x240 bmp.
I created a frame bmp at 320x240 resolution
It displays corrupted, so tried the turtle.bmp and same corrupted, thought it was the uSD playing up so reformatted and reloaded files , same corrupted so thought try with the Gfx demo.spin and the frame bmp displays fine and also the turtle bmp also, so from this I'm assuming it's to do with the wavplayer code not liking big files at 320x240? the smaller bmp for the playbutton shows ok in the wavplayer so the issue just seems to be with larger files or I should say larger resolutions
Looks great, thanks for sharing. QMP Paint could definitely use more features...
PSB and PTP Paint let you do things like switch between line and pixel mode and set background, etc...
As I think of new ideas or functions and they are within my programming ability I will add them.
Have now added the ability to change the colour scheme or look by the touch buttons.
Hint: hold down either the Home icon or the Email icon and wait as there are sometimes gaps between different schemes where it looks like the screen is dark but it's still scrolling through various screen layouts, it's just some are dark
tap the note icon to accept the look and continue to the paint program.
Screen now shows what colour paint has been selected
Hi Rayman, I thought I might be getting somewhere with the wavplayer code in creating the coords for the stop button and assigning decimal 2 as the result for pressing it with the code snippet below:
DAT 'define on-screen buttons
nButtons byte 1
Buttons byte
buttonPlay byte 152,193,173,216,1 'x1,x2,y1,y2,handler 1=playbutton result in Getbutton routine
buttonStop byte 75,85,189,199,2 'coords of stop button 2=stopbutton
That last number, "1", is what the "GetButton" function will return when button is pushed.
But it seems that the repeat loop
repeat 'wait until play button pushed
WaitStylusDown
WaitStylusUp
Ser.tx("*")
ser.dec(touchx)
ser.tx(" ")
ser.dec(touchy)
ser.str(string(" Button pressed= "))
ser.dec(Buttons)
until GetButton==1
ser.dec(Buttons)
in main which I assumed from the statement above would return 2 is not doing so?
As you will see I added the ser.str and ser.dec(Buttons) to see what was going on.
In PST it showed that pressing the stop button returned decimal 152, ok fair enough I thought I'll write a routine that says 152 is the stop button instead of 2
Until I tried several different touches around the screen and they all returned decimal 152, not good!
Touching the play button returns 152152
So question is where is the 1 for the play button touch being stored? As the repeat loop does quit with 1 .
Or is the repeat loop just quitting because 1 is the equivalent of TRUE ie the DAT code above is not doing what I assumed it was supposed to from the quote above?
Yes I realised my mistake today but havn't been able to try it out till tonight, have replace buttons with GetButton it does return a 1 when the play button is pressed but the stop button returns 0 not 2? Perhaps my coords are wrong? I'll try mapping the stop button again
clicking within the red rectangle which is perfectly aligned over the stop button just returns 0(zero) every time
with the code above am I correctly reading the DAT for the Stop button below? The red rectangle does appear in the correct position so it must be correct yet it returns only zero??
DAT 'define on-screen buttons
nButtons byte 1
Buttons byte
buttonPlay byte 152,193,173,216,1 'x1,x2,y1,y2,handler 1=playbutton result in Getbutton routine
buttonStop byte 75,85,189,199,2 'coords of stop button 2=stopbutton
To stop the wav player playing each time I tried clicking around the screen I also tried changing the 1 in the buttonPlay byte line to another number 3 and when clicking on the play button 3 was returned correctly in PST
Edit:
That was it! am getting a returned value of 2 now although I need to expand the rectangle a little as it's a bit too small and the stylus doesn't always hit the sweet spot.
Thanks very much Rayman, with this knowledge I can now dabble a bit more and map all the buttons and hopefully write a routine to action the button presses, will let you know how I progress.
Made a few cosmetic changes to the look of the Wav Player.
I am having trouble trying to work out how to get the stop button to control the wav player, I thought of just using cogstop but that didn't seem to work the way intended.
The way I understand the code so far is that the main program including the touchscreen control is in the first cog and then the PlayWav method opens a second cog,
so two cogs are running (not sure about the other objects opening any more cogs)
So if we just take the it that main and PlayWav ( or is the Pasm bit running in it's own cog?) are in different cogs running together I'm having problems working out how to break into the Playwav routine to stop playing the wav file, It looks like the method fills two buffers with the wav's data and plays in two repeat loops until the buffers are empty.
I've tried to quit the two loops by putting repeat until getbuttons==2 at the start of both loops but the trouble I'm having is getting the getbuttons method to look at the touchscreen input whilst the PlayWav method is running, I tried putting the touchscreen section in it's own method called CheckTouch and calling that within the two loops but all that does is interrupt the playing of the wav??
I tried inserting the call to CheckTouch at different places within the two loops but had no luck each time it just stopped it playing the wav and you just get a buzz in the earphones.
So question is how to get the program to look at the touchscreen input without interrupting the player?
I'm at a loss as to how to progress with my limited knowledge, so meantime have been playing around with the cosmetics, so I hope you like the new look.
Looking pretty good!
You can use the bTouchDown function (returns true or false) to tell if the screen is being touched.
You can then use the code from WaitStylusDown to get x and y values...
But really, we are probably going to need another cog, dedicated to looking at the touchscreen for this.
It may be too unreliable to juggle checking the touchscreen and filling the play buffers from SD...
I have some ideas on how to do this a lot better, just not the time yet...
Comments
Artist and album title can be changed to whatever is needed.
Read the readme txt for further info
The play button changes to a pause button but the code needs to be written to toggle the bitmaps back and forth and also to pause the wavs
I think that this will involve putting the touchscreen code in another cog so a repeat loop can run indefinitely and pass presses to the main program this will also make it easier to have toggles like the backlight on and off
I checked the current draw with the player and all leds running and it came out to approx 155ma running at 4.5 V on battery power, is this ok for an unpowered USB port? Noticed the usb plug that goes into the laptop gets warm.
One question does the screen allow support for using an alpha channel on the bitmaps as it would save having to change the bitmaps backgrounds whenever the main background is changed.
Using square buttons would probably solve this problem.
Another way might be to use 4 or 8 bit bitmaps with the background color forced to be some constant color number. Then, you could just change the palette so the image background color matched the screen background.
All a lot of work compared to using rectangular button areas...
an editor like zoner photo studio allows you to enter the RGB values that you chose for the background to the bitmap fill
I'm trying to understand from the code how the touchscreen area for the play button is worked out. so that could be applied to the different controls
Is this done with a square over the button or does the code work out the shape and size of the button?
(Probably not the best way). You can probably still find, commented out, the line that draws the rectangle.
I'll look for the code and experiment a bit
Found the code but why are there dashes between the last three numbers 240-51-20 rather than commas are those numbers being subtracted from 240 and which number corresponds to the correct buttonPlay array variable?
sorry to keep asking questions but with this knowledge I can look at creating touchscreen areas for the other controls in advance of the code for actually doing something with the press.
That's if you don't mind me doing so
Was being lazy...
what does the 1 at the end do I tried increasing this when drawing the rectangle as I presumed it was thickness of the line but changing it did nothing?
The other numbers are x and y coordinates of the button on the screen. X should be between 0 and 319 and Y should
be between 0 and 239. negative numbers won't give an error, but shouldn't be used...
I can use 2 to denote the stop button which I am in the process of designing for pressed or set
I'll redo the code to get rid of the neg numbers should be a doddle now to map the Next track and previous track buttons too
The action code will take me a time to work out unless you are already on the case with that?
What about the idea about the touchscreen and relevant code in a different cog and perhaps in it's own object, would that be necessary to allow touches whilst the wav plays?
Edit: New coordinate for stopbutton without neg numbers:
Thanks Rayman for those snippets about the code it's really helping me to understand it
Like in the Draw rectangle code the way you can just name the colour rather than having to type in the RGB values
Is there a table of what colours you can use that way with the screen? Is that the eight colours mentioned in the paint code?
Worked out the problem with sorting the tracks, load them one at a time in order rather than copying them altogether to the uSD
New designed Stop Button(Thank heaven for the clone button feature in zoner photo studio, used to get gradiant for curve effect from adjacent button)
Going to have to make several versions for diffent scenarios such as play button stop unset play set to pause and stop button either set or not etc etc
or will I be able to draw a bitmap at a location like you can draw a rectangle? then it would just be a case of saving button bitmaps rather than the whole control bar for each scenario.
, will have to change coords in the code before posting for it tomorrow too tired to do that tonight:
If you get a chance please have a look as I'd like comments about whether you think it looks ok or not., the three bitmaps are included in the archive and you need to click the play button to start the sequence.
Bitmaps for next and prev buttons to follow later
Thanks Rayman I appreciate that
Another question, does the bitmap draw wipe the entire screen ie if I drew a bitmap for a frame and then drew a bitmap for the controls would the controls bitmap erase the entire screen or only the portion of screen below where it's placed? The answer will decide which way to go in designing the Wavplayer screen
I created a frame bmp at 320x240 resolution
It displays corrupted, so tried the turtle.bmp and same corrupted, thought it was the uSD playing up so reformatted and reloaded files , same corrupted so thought try with the Gfx demo.spin and the frame bmp displays fine and also the turtle bmp also, so from this I'm assuming it's to do with the wavplayer code not liking big files at 320x240? the smaller bmp for the playbutton shows ok in the wavplayer so the issue just seems to be with larger files or I should say larger resolutions
biWidth:=214
Don't know how that got in there.... Must have been while troubleshooting something...
Edit: It works great now thanks
PSB and PTP Paint let you do things like switch between line and pixel mode and set background, etc...
As I think of new ideas or functions and they are within my programming ability I will add them.
Have now added the ability to change the colour scheme or look by the touch buttons.
Hint: hold down either the Home icon or the Email icon and wait as there are sometimes gaps between different schemes where it looks like the screen is dark but it's still scrolling through various screen layouts, it's just some are dark
tap the note icon to accept the look and continue to the paint program.
Screen now shows what colour paint has been selected
But it seems that the repeat loop
in main which I assumed from the statement above would return 2 is not doing so?
As you will see I added the ser.str and ser.dec(Buttons) to see what was going on.
In PST it showed that pressing the stop button returned decimal 152, ok fair enough I thought I'll write a routine that says 152 is the stop button instead of 2
Until I tried several different touches around the screen and they all returned decimal 152, not good!
Touching the play button returns 152152
So question is where is the 1 for the play button touch being stored? As the repeat loop does quit with 1 .
Or is the repeat loop just quitting because 1 is the equivalent of TRUE ie the DAT code above is not doing what I assumed it was supposed to from the quote above?
"Buttons" just equals the first byte defined here:
Buttons byte
buttonPlay byte 152,193,173,216,1
which is 152.
Maybe try ser.dec(GetButton) instead of ser.dec(Buttons)...
That might be useful to see where it is...
Haven't actually tried it with 2 buttons, but hopefully it works...
clicking within the red rectangle which is perfectly aligned over the stop button just returns 0(zero) every time
with the code above am I correctly reading the DAT for the Stop button below? The red rectangle does appear in the correct position so it must be correct yet it returns only zero??
To stop the wav player playing each time I tried clicking around the screen I also tried changing the 1 in the buttonPlay byte line to another number 3 and when clicking on the play button 3 was returned correctly in PST
nButtons byte 1
To:
nButtons byte 2
The nButtons variable tells the code how many buttons to look at...
Edit:
That was it! am getting a returned value of 2 now although I need to expand the rectangle a little as it's a bit too small and the stylus doesn't always hit the sweet spot.
Thanks very much Rayman, with this knowledge I can now dabble a bit more and map all the buttons and hopefully write a routine to action the button presses, will let you know how I progress.
I am having trouble trying to work out how to get the stop button to control the wav player, I thought of just using cogstop but that didn't seem to work the way intended.
The way I understand the code so far is that the main program including the touchscreen control is in the first cog and then the PlayWav method opens a second cog,
so two cogs are running (not sure about the other objects opening any more cogs)
So if we just take the it that main and PlayWav ( or is the Pasm bit running in it's own cog?) are in different cogs running together I'm having problems working out how to break into the Playwav routine to stop playing the wav file, It looks like the method fills two buffers with the wav's data and plays in two repeat loops until the buffers are empty.
I've tried to quit the two loops by putting repeat until getbuttons==2 at the start of both loops but the trouble I'm having is getting the getbuttons method to look at the touchscreen input whilst the PlayWav method is running, I tried putting the touchscreen section in it's own method called CheckTouch and calling that within the two loops but all that does is interrupt the playing of the wav??
I tried inserting the call to CheckTouch at different places within the two loops but had no luck each time it just stopped it playing the wav and you just get a buzz in the earphones.
So question is how to get the program to look at the touchscreen input without interrupting the player?
I'm at a loss as to how to progress with my limited knowledge, so meantime have been playing around with the cosmetics, so I hope you like the new look.
You can use the bTouchDown function (returns true or false) to tell if the screen is being touched.
You can then use the code from WaitStylusDown to get x and y values...
But really, we are probably going to need another cog, dedicated to looking at the touchscreen for this.
It may be too unreliable to juggle checking the touchscreen and filling the play buffers from SD...
I have some ideas on how to do this a lot better, just not the time yet...