View Full Version : Multiple buttons, one special case

08-21-2005, 09:55 PM

I'm working on a controller circuit for a paintball gun that involves an LCD screen. I've borrowed heavily from NV #62 on using menus, and I had a question about how to treat the trigger button, which is a special case compared to the other buttons.

Here is a list of the buttons I'm dealing with:


In NV62 Jon Williams dealt with debouncing multiple inputs by ANDing a byte the inputs with a temp byte repeatedly. This definitely works for the mode, select, and safety, but for the trigger I'm looking for some special behavior I previously achieved using BUTTON.

The special behavior is this: The trigger is used three modes, semi, burst, and auto.

In semi the trigger should fire only once until released (BUTTON delay = 255 for no repeat)
In burst the trigger should fire multiple shots only once until released (BUTTON delay = 255 with a FOR loop)
In auto the trigger should fire continuously until released (BUTTON with a delay for auto-repeat)

How can I achieve this in my new code while I'm looking at these other buttons?



Chris Savage
08-21-2005, 11:41 PM

You may be overcomplicating things now. You have new code, yes, but, unless I am missing something, why can't the code handle the firing modes based on the trigger being pressed? That way the trigger button doesn't need to be handled in a special way. Unless the code you refer to won't let you hold it down.I would just make it so that when the trigger is pressed, the code decides based on the mode how to trigger the solenoid or whatever is firing your paintball gun.

Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

08-22-2005, 06:19 AM
I certainly don't want to overcomplicate things. My old code used the BUTTON command's delay = 255 to accomplish only one fire per trigger pull, and I used button's autorepeat feature for fully automatic. I just don't know how to accomplish those things using the multi-input debounce code. Is it possible to use the BUTTON code for the trigger and the multi-input debounce code for the rest?

But I would really like to learn how to accomplish the trigger button features without BUTTON, if you could show me how.

Thank you,


08-29-2005, 04:29 AM
Still working on getting the behavior I want from the Trigger and Safety buttons. Help is very much appreciated. Here is the behavior I'm trying to achieve.

1. Safety:

When held down, will display "SAFE" in place of shot count (4-digit number) in main screen, until released (this is mechanical rotary level that acts on a lever snap switch, so when the mechanical lever is in SAFE the button will be held down).
Increment fire mode (semi, burst, full) each time safety is pressed (or pressed and released, doesn't matter)

2. Trigger:

In semi mode, I would like adjustable debounce but no repeat.

With the BUTTON command I can get no repeat with the delay=255 option, but the debounce time is not adjustable. From the Getkey routine I can see how the button command likely works, except for how it achieves the no-repeat. Can someone show me the BUTTON command in software or how to write the Getkey routine with no repeat?

I'm thinking it might involve a bit variable that gets flipped when the button is pressed and sends out a pulse then flips back when the button is released.

Attached is my latest code, I'm using the BUTTON and Getkey subroutine, but not getting the behavior I'm looking for.

Thank you,


09-02-2005, 03:53 AM
Just wondering if anyone can help getting the button behavior in the above post?

Thanks for all your help,