Let's Make Robots!

What Picaxe Command to use?

Iam makeing a nerf bomb for my sons's and iam stuck on what command to use.Iam useing a bread board and jumper cables so they have to pull out the jumper cables to stop the timer.

I have the jumper cables on input pin 0 to 3 and a button on input pin 7 and a buzzer on output pin 6 the command iam looking for is to make the button on input pin 7 cycle though the loops  ie;

main: if pinc.0 = 0 then buzz1


buzz1: high b.6 

           pause 6000

           low b.6

           goto loop1

loop1: if pinc.1 = 0 then buzz2

buzz2: high b.6

           pause 6000

           low b.6 

          goto loop2

loop2: if pinc.2 =0 then buzz3

buzz3: high b.6 

           pause 6000

           low b. 6

           goto loop3

and so on.The command iam looking for it to make the button on pin7.Say if pressed once the goto loop1 if pressed twice then goto loop2.Iam not looking for someone to give me a code just point me the right way.Iam using  PICAXE 28X1.

Thanks for your time

Comment viewing options

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

thankyou all for the info i will take it all on board and hopefully have it up and runing soon.

merser my kids are in to nerf guns and my son see on youtube airsoft bomb's so i said i wll make them a nerf bomb lol.


Birdmun is right. Your goto statements do nothing to alter the flow of the code. A goto is meant to alter the sequence of code running by jumping to somewhere else in the program. But because the jump is to the next line it is the same sequence as if you never had the goto in there.

Also your loops contain exactly the same code. You can use it once and use a gosub to goto the loop and then return to come back to the instruction after it. Using botfins example for the button. hopefully this achieves what you want. I must admit I have no idea what a nerf bomb is. lol.

  eg. btn_pressed

  1. If pinc.7 = 1 then pause 300      ;" if button on pinc.7 is pressed wait
  2. else goto btn_pressed              ;" or another part of the program
  3. if pinc.7 = 1 then goto loop        ;" is it still pressed then run loop. this is simple debouncing in software
  4. goto     btn_pressed                 ;" if it isn't pressed loop until it is pressed or goto another part of the program
  5. loop
  6. if pinc.0 = 0 then gosub buzz
  7. if pinc.1 = 0 then gosub buzz
  8. if pinc.2 = 0 then gosub buzz
  9. if pinc.3 = 0 then gosub buzz
  10. goto btn_pressed                     ;" or another part of the program
  11. buzz
  12. high b.6
  13. pause 6000
  14. low b.6
  15. return





Mercer is incorrect about your loops. They appear to be the same, but Calculon notices that each loop is testing a different input (eg. loop1 looks at pinc.1). It appears the idea is to test the specific pin and the specific pin only. 

So about your goals here, is this correct: You want the picaxe to test an input pin continually, and the buttonPin button will determine which pin is being tested?

If so, that's easy enough, but what are you ultimately trying to accomplish? Do you want to stay in a continual testing loop on a given pin UNTIL the input is 0? What happens then? Move on to the next loop? Why the pint 7 button then? And after buzz3, do you go back to buzz 1?

The bomb has a timer and the kids must remove the jumper wire before it reaches zero or it "explodes"? Is that the idea? That's great! Disregard Calculon's last paragraph.

it looks as though you will 'fall through'.
For example:

loop1: if pinC.1 = 0 then buzz2
buzz2: high B.6

Your program will hit the label loop1, check the if statement, and then, whether or not C.1 is low, will fall on through to the buzz2 label.

Re: your original question
You will need to debounce a mechanical switch, otherwise, you will get multiple hits no matter what. The only way that I can think of checking for mutliple presses would be to use an interrupt. You would set up your routine to check how many times the button was hit over a short period. 

if pin7 = 1 then pause 300 'if button is pressed wait 0.3s

if pin7 = 1 then goto loop2 'check again
 else goto loop1 


if pinc7 = 1 then (cycle though the loop's some how )