Shop OBEX P1 Docs P2 Docs Learn Events
Button Command — Parallax Forums

Button Command

MRMR Posts: 46
edited 2008-03-10 16:19 in BASIC Stamp
I am new at this.



I have a 12 Digit keypad connected through resistors to the Basic Stamp. I know that each key works correctly because of this test

program.

Note: I try not to use GOTO, I try to use DO LOOP.

' {$STAMP BS2p}
' {$PBASIC 2.5}


Keypad:
MAINIO
IF IN0=0 THEN Keypress
IF IN1=0 THEN Keypress
IF IN2=0 THEN keypress
IF IN3=0 THEN keypress
IF IN4=0 THEN keypress
IF IN5=0 THEN keypress
IF IN6=0 THEN keypress
IF IN7=0 THEN keypress
IF IN8=0 THEN keypress
IF IN9=0 THEN keypress
IF IN10=0 THEN keypress
IF IN11=0 THEN keypress
GOTO Keypad


Keypress:
DEBUG "A Key Has Been Pressed!"
PAUSE 500
GOTO keypad

The problem:

I have another program that uses the button command and it works with the first key press however I can't get it to work after that first key press. After this first key press is the keypad remaining low?

Here is the code.

' {$STAMP BS2p}
' {$PBASIC 2.5}

Month VAR Nib
Day1 VAR Nib
Day2 VAR Nib
Year1 VAR Nib
Year2 VAR Nib
Year3 VAR Nib
Year4 VAR Nib
Hour1 VAR Nib
Hour2 VAR Nib
Minute1 VAR Nib
Minute2 VAR Nib
Btn VAR Byte
Btn2 VAR Byte
Test VAR Nib

zero VAR Nib
One VAR Nib
two VAR Nib
three VAR Nib
four VAR Nib
five VAR Nib
six VAR Nib
seven VAR Nib
eight VAR Nib
nine VAR Nib


Month_Select:
MAINIO
BUTTON 1,0,255,255,Btn,1,January 'First Key Press Selection.
BUTTON 2,0,255,255,Btn,1,February
BUTTON 3,0,255,255,Btn,1,March
BUTTON 4,0,255,255,Btn,1,April
BUTTON 5,0,255,255,Btn,1,May
BUTTON 6,0,255,255,Btn,1,June
BUTTON 7,0,255,255,Btn,1,July
BUTTON 8,0,255,255,Btn,1,August
BUTTON 9,0,255,255,Btn,1,September
BUTTON 10,0,255,255,Btn,1,October
BUTTON 0,0,255,255,Btn,1,November
BUTTON 11,0,255,255,Btn,1,December
GOTO Month_Select

Day1_Select: 'When the CODE Executes Here it goes directly to Day1_One. Why?
MAINIO
BUTTON 1,0,255,255,Btn2,1,Day1_One ' Why Does the button command not work here?
BUTTON 2,0,255,255,Btn2,1,Day1_Two
BUTTON 3,0,255,255,Btn2,1,Day1_Three
BUTTON 0,0,255,255,Btn2,1,Day1_Zero
GOTO Day1_Select



DTX:
AUXIO
SEROUT 0\1, 9600,[noparse][[/noparse]Test]
PAUSE 50
SEROUT 0\1, 9600,[noparse][[/noparse]Month]
PAUSE 50
SEROUT 0\1, 9600,[noparse][[/noparse]day1]
PAUSE 50
SEROUT 0\1, 9600,[noparse][[/noparse]day2]
PAUSE 50
SEROUT 0\1, 9600,[noparse][[/noparse]year1]
PAUSE 50
SEROUT 0\1, 9600,[noparse][[/noparse]year2]
PAUSE 50
SEROUT 0\1, 9600,[noparse][[/noparse]year3]
PAUSE 50
SEROUT 0\1, 9600,[noparse][[/noparse]year4]
PAUSE 50
SEROUT 0\1, 9600,[noparse][[/noparse]Hour1]
PAUSE 50
SEROUT 0\1, 9600,[noparse][[/noparse]Hour2]
PAUSE 50
SEROUT 0\1, 9600,[noparse][[/noparse]Minute1]
PAUSE 50
SEROUT 0\1, 9600,[noparse][[/noparse]Minute2]
GOTO Month_Select


January:
Month=%1000
Test=1
GOTO Day1_Select

February:
Month=%0100
Test=1
GOTO DTX

March:
Month=%1100
Test=1
GOTO DTX

April:
Month=%0010
Test=1
GOTO DTX

May:
Month=%1010
Test=1
GOTO DTX

June:
Month=%0110
Test=1
GOTO DTX

July:
Month=%1110
Test=1
GOTO DTX

August:
Month=%0001
Test=1
GOTO DTX

September:
Month=%1001
Test=1
GOTO DTX

October:
Month=%0101
Test=1
GOTO DTX

November:
Month=%1101
Test=1
GOTO DTX

December:
Month=%0011
Test=1
GOTO DTX


Day1_Zero:
Day1=%0000
Test=1
GOTO DTX

Day1_One:
Day1=%1000
Test=1
GOTO DTX

Day1_Two:
Day1=%0100
Test=1
GOTO DTX

Day1_Three:
Day1=%1100
Test=1
GOTO DTX

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-03-10 15:14
    MR -

    Please download Nuts and Volts Column 22 which contains a keypad scan routine. BUTTON is not a good choice for keypads. Here is the Parallax web page where that program can be found:
    http://www.parallax.com/Resources/NutsVoltsColumns/NutsVoltsVolume1/tabid/444/Default.aspx

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Programming can't be all that difficult, it's nothing but 1's and 0's
  • MRMR Posts: 46
    edited 2008-03-10 15:35
    My Circuit isn't a Matrix Keypad.


    What should I do?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-10 15:52
    The variable associated with the BUTTON statement ("Btn", "Btn2") is supposed to be unique to the button involved while you're using the same variable for all of the buttons. Reread the manual section for the BUTTON statement.
  • MRMR Posts: 46
    edited 2008-03-10 16:19
    I run out of variable space using button. Bruce said its not a good Idea to use it for a keypad.

    I don't have matrix keypad is there any way to "Clear" the variable to use it with different keys?


    I.E. Use one button variable then clear it for the next keypress?
Sign In or Register to comment.