Idea for a pocket sounder

jay4708

New Member
Hi

My son and I are new to Picaxe and would much appreciate some help with our first little project.

I asked my son what he would like to make and he came up with a great idea. He wants to build a little box with a button on it that when pressed it plays a tune (Mission Impossible), if the button is pressed twice or three times it plays different tunes.

The bit of the coding I can't get my head around is the multiple button press, how do I write the code so it plays a different tune if it is pressed twice or three times?

Thanks
John
 

tony_g

Senior Member
i am using something similar on one of my RC circuits and using only one input button this is what i use for it :

Code:
button_select:
pause 150
inc b8
if b8=6 then let b8=1 endif

select case b8

case 1
goto xxx
case 2
goto xxx
case 3
goto xxx
case 4
goto xxx
case 5
goto xxx
end select
you would need to change the variable b8 to one that is not being used elsewhere in your code and also the "if b8=6 then let b8=1 endif" statement to suit how many switch presses you want to go through before it rolls back round to the first again e.g if you only want to go through 3 then "if b8=4 then let b8=1 endif so that once you get to 3 and push it again it will go back to the 1st.

then just put your goto functions to your individual tune programs.

i use this to cycle through 5 selectable mosfet outputs to turn on or off RC lighting and other things on a scale truck and in the full code its used in it responds reasonably fast to either switch or reciever inputs and cycles from the 1st output to the 5th then rolls back over to the 1st again.

tony
 

tony_g

Senior Member
another option if you want the code to wait a set period and then decide which tune to play then you can use this:

Code:
bttn:
pause 150
let b6=b6+1
if b6=4 then let b6 =1 endif

let time =0
do
pause 1
loop until pinc.3=1 or time =3
if pinc.3 = 1 then bttn:

select case b6

case 1
goto xxx
case 2
goto xxx
case 3
goto xxx

end select
the first idea i posted prior to this one will allow you to press the button and it will go straight to its designated tune to run, this one will wait a period of time after a button press to see if another button press is to be logged in the counter variable.

so if you wanted tune 2 you would press the button twice then there would be a short delay while the code looks to see if you are going to push it again before deciding which program flow to jump to.

tony
 

jay4708

New Member
Tony your a star, thanks for the detailed replies, I've not read the code yet but will do later and get back to you.

Thank you.
 
Top