Shop OBEX P1 Docs P2 Docs Learn Events
Keypad question - the next step — Parallax Forums

Keypad question - the next step

cicacica Posts: 11
edited 2006-05-26 01:32 in BASIC Stamp
Hi-

I've been combing this forum as well as other resources and I can't seem to find an answer to this one.

I have a BS2 that has 4 buttons on P0-P3. I've used the debounce code to determine which of the 4 buttons are being pressed, and before reinventing the wheel, I was wondering if anyone has already written a routine to extract a 4-digit code from keypresses.

Specifically, I'm looking for a timer to start upon the first keypress, and if there aren't 4 button presses within 20 seconds, to clear all button presses from memory. I'm also trying to avoid keypress repeats. In this area, I was thinking of not allowing a 2nd, 3rd, 4th press to be recorded until the previous button registers as being released. I'm planning on giving feedback to the user that each keypress has been accepted via the LCD.

I'm pretty sure I can write this, but I'll probably end up filling up the stamps memory burger.gif

Thanks,
-Tom

Comments

  • boeboyboeboy Posts: 301
    edited 2006-05-26 01:32
    here it is i have it set up so that it will debug it but you can change that it is just fore starters and hope you like itsmilewinkgrin.gif !!



    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    'vars
    buttspace VAR Byte
    res1··· VAR Bit 'result
    res2··· VAR Bit 'result
    res3··· VAR Bit 'result
    res4··· VAR Bit 'result
    butwait CON 20000 '20 seconds
    but1··· PIN 0 'pins
    but2··· PIN 1
    but3··· PIN 2
    but4··· PIN 3

    main:
    BUTTON but1, 0, 255, 0, buttspace , 1, addone:

    BUTTON but1, 0, 255, 0, buttspace , 1, addone2:

    BUTTON but1, 0, 255, 0, buttspace , 1, addone3:

    BUTTON but1, 0, 255, 0, buttspace , 1, addone4:

    DEBUG DEC res1

    DEBUG DEC res2 ,CR

    DEBUG DEC res3 ,CR

    DEBUG DEC res4 ,CR

    pause·buttwait

    res1 = 0
    res2 = 0
    res3 = 0
    res4 = 0
    GOTO main


    'subs
    addone:· 'add 1 to res1
    res1 = 1
    RETURN

    addone2:· 'add 1 to res2
    res2 = 1
    RETURN

    addone3:· 'add 1 to res3
    res3 = 1
    RETURN

    addone4:· 'add 1 to res4
    res4 = 1
    RETURN
Sign In or Register to comment.