Let's Make Robots!

Question: Using Multiple 'taps' on button to subroutine branch

PICEAXE 18M2.  I would like to use 'taps' on a single button to select different subrountines.

For example, 'tap' once on the button switch to select one subroutine.  Double 'tap' selects a different subroutine.  Triple 'tap' selects still a different subroutine.  Four 'taps' ......   Okay, you get the idea.

Is this possible?  Wait, of course the 'tap' once example is a no brainer, so let's move to the multiple 'taps'.  What commands would be use?  Any hints?


Comment viewing options

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

I have some code for this! I will dig it up quickly. :)

edit: forgot the "LY" Duh! 

Here we go: http://dl.dropbox.com/u/20400183/Paino.bas



Thanks.  Haven't looked at it yet, but wanted to let you know I got it in case you wanted to remove it from your public directory. Thanks again.

My suggestion is to count  how much  time is needed to raise the i variable  of a for statement from 0 to 1 and then make a function

that does this one and then goes to the code below .

Well its not the best idea but if this can be counted then it is possible ..


I just figured something out... The major problem here is the fact that picaxe does not allow you to get a hold of any kind of timer! There is no "millis" or "seconds" command --all you have is the pause... Hmmm....

In my mind, the only way this is going to work is to make your own timer. The simplest version of this I can think of is to take a given period of time (maybe somewhere around 750ms?) and just count pulses within that time. One would have to debounce with some caps and the like --I think a "debounce pause" would muck things up.

From there, you could make your "timer" via a simple loop. Do a for-next with a button check and a quick pause and loop it for as long as you want your "given period of time" to be. An addition could be that each time the button is pushed, a little more time is added to the "check the button" period.

I can't think of a way to do a timeout after each button push (to then know that was the "last" push and thus, go with our "count"). Man, this lack of any kind of timer on a picaxe is a pain. I have gotten spoiled by Arduino and the Prop...

Could you be more specific about what you are thinking about doing? I get the impression my original suggestion may have been a bit over the top. Especially, now that you are wanting to look at the code from the knock box. What I am getting at is, interrupts are only required for something that you feel needs to have attention paid to it as soon as it happens rather than when the code gets to the point of being able to check the button presses.

Thanks, birdmum.

The application is for the robot hand I am building.  It is like serveral others, but I would like to add two features.  One is a serial LCD display describing the gesture.  I be I'll be asking questions about that later...

For the button press (back on my original question) is to select the specific gesture subroutine I want the robot hand to make.

For example, two quick button taps may be "gosub Shoot_Finger".  Three quick button taps may be "gosub Thumbs_Up".  Etc.

Then I got to thinking about the Knock Box and prehaps using a 'tap-tap-pause-tap', for example; as a decision branch.  I don't really need an interupt, per say, as I can sit the PICAXE in a loop waiting for the button taps.

Oddbot posted a tip on how to use one button on an Arduino to switch between different modes based on a code written to the EEPROM. Perhaps a similar approach would work on a PICAXE? It is a different chipset, so I'm not sure.

Instead of counting taps, each button press toggle the next mode.

Does anyone have the code AndyGadget used for his "Picaxe Poltergeist"?

See: http://www.instructables.com/id/Piecax-the-Poltergeist-A-Troublesome-Spirit-in-a/

It's on the instructables site for paid members, but I'm a instructable freeloader.

The code is on the bottom of the last page. You do not have to pay to see any instructables or to download files. A window may pop up asking you to become a member, but that does not mean you have to.


I see the docs on that page, but I can't for the life of me get one to load without a password.