View Full Version : Button Variable

Lucas Harlem
01-28-2006, 09:45 PM
I am using several button command statements to make a basic keypad.

I have nine buttons 1 - 9 for a keypad.

When a button is pressed say for example key 1, it branches to that address and shifts out a 4 bit nibble to a shift register which is in turn connected to a seven segment dual digit display. Okay works great, but when I try to press another button it doesn't work. How do I clear this variable workspace that button uses? Should each button have a different workspace variable.

For example: Should button 1 use BN1 as its variable workspace?
and Should Button 2 use BN2 as its variable workspace? etc etc


BUTTON 1,0,255,255,BN1,1,Adr1
BUTTON 2,0,255,255,BN1,1,Adr2


BUTTON 1,0,255,255,BN1,1,Adr1
BUTTON 2,0,255,255,BN2,1,Adr2

Is there a way to clear this button variable without resetting the stamp?

Post Edited (Lucas Harlem) : 1/28/2006 2:48:40 PM GMT

Jon Williams
01-28-2006, 11:23 PM
BUTTON is not really the best choice in that kind of application -- with a small bit of code you can scan as many buttons as you like in one subroutine and the state of any pressed buttons is stored in a variable. Here's an example that scans four buttons:

btns = %1111
FOR idx = 1 TO 5
btns = btns & ~BtnBus

By modifying the size of the "btns" variable you can scan up to 16 buttons if you want. The complete explanation is in StampWorks:


Jon Williams
Applications Engineer, Parallax