Shop OBEX P1 Docs P2 Docs Learn Events
keypad counter — Parallax Forums

keypad counter

mike5321mike5321 Posts: 4
edited 2005-07-02 11:38 in BASIC Stamp
I want to count and store to eeprom the number of times each key is pressed on a 4x4 keypad. I have it working for the most part but would like some help to reduce all of the·"IF "statements. Attached is the code.


thank you

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-30 12:56
    Your program wants to use Words but you don't have enough space.· Since you can't press keys fast enough and enough times to kill your EEPROM, I suggest you dump the RAM variables for the key count and save them directly to EE.· You can do it like this:

    Main:
    · DO
    ··· GOSUB KeyScan
    · LOOP UNTIL (press <> 0)······················· ' wait for key press
    · DEBUG "Key pressed = ", HEX key, CR··········· ' show it

    · READ (key * 2), Word temp····················· '·read·current key value
    · temp = temp + 1······························· ' increment
    · WRITE (key * 2), Word·temp···· ··············· ' save updated count

    · FOR key = 0 TO 12····························· ' show all counters
    ··· READ (key * 2), temp························ ' read the key count
    ··· DEBUG "Key ", DEC2, ": ", DEC temp, CR·······' show it
    · NEXT

    · GOTO Main

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • mike5321mike5321 Posts: 4
    edited 2005-07-02 11:38
    This worked great.Thanks for your help.
Sign In or Register to comment.