Shop OBEX P1 Docs P2 Docs Learn Events
MemKey — Parallax Forums

MemKey

Eric REric R Posts: 225
edited 2006-04-25 15:44 in General Discussion
Using a MemKey with a 4x5 keypad. This keypad has a·few extra buttons that I have no use for such as "ABC", right, left, up and down arrows. As expected, each key returns a value, however, is there a way to write a key out so it is not functional? I have read NV59,·60,·S3 documentation, searched the forum and Google·but am unable to locate a solution. I hate to think that I am stuck adding a bunch of lines stating "IF key = X then"
I know it would be easier to find another keypad but the company I work for already stocks it making replacements easy to obtain. While it is not that big of an issue, the occasional bump of an unneeded key can be frustrating.

I did program the extra keys to return $00 but that gives a back hash each time one is pressed. I could combine that with one "IF key =·$00 THEN" statement and loop it back to·ignore the key·but I would rather disable if possible.

Thanks in advance!

·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-22 04:59
    Eric,

    ·· Why can't you just ignore the extra keypress data in your program?· That would be easiest.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Eric REric R Posts: 225
    edited 2006-04-22 05:44
    Chris,

    That was the idea with the "IF key =·$00 THEN" statement. I will probably go that route. Just didn't want to overlook the obvious. Thanks for your help.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-22 06:01
    Eric,

    ·· What I meant was, you can act on the key values you are looking for, and don't even check for invalid keys.· You don't need to.· If you have a loop testing for values and you have conditionals dealing with those values then you can just not test for values you don't want.· Ignore them.· Don't write any code for them.· Your code will only deal with what you're expecting...I hope I am a little mroe clear...It's late...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Eric REric R Posts: 225
    edited 2006-04-22 22:13
    Thanks Chris,

    I have read your post about a dozen times now "you can act on the key values you are looking for, and don't even check for invalid keys" I do not see a way with my current code structure to accomplish this. I should say that I am allowing the user to enter a random 5 digit number that will display in real time as it is entered. With that being said, I just added a lookdown table that, when valid, sends the sequence back to the last keystroke just before the SEROUT command to the LCD. While I found two ways of handling this issue I am sure there are others. Being my first MemKey, my program is a little rough but it will get better as I lean more.

    For the MemKey having its 7th birthday I was really suprised at how little documentation and coding examples· were kicking around.

    Once again, thanks, I think I have it nailed down and working well.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-04-24 19:06
    Chris is talking about using a CASE statement, where only those conditions you specify are acted upon. If you post the code section dealing with handling keys we would be better equipped to offer advice.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1+1=10
  • Eric REric R Posts: 225
    edited 2006-04-24 21:48
    Thus far I have managed to fill the memory of a BS2 for this little program. Let me clean it up a little so you guys don't knock my pick·-n- sort one key at a time method. Well to be honest, that is what you will get later tonight as I have found no other way that I can make it work. lol.gif
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-04-24 22:35
    In pseudo-code I would do something like:


    For i=0 to 4
      do
        get_key
        if key is num
           total = total*10 + key
           notnum = false
        else
           notnum = true
        endif
      while notnum
    Next i
    


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1+1=10
  • Eric REric R Posts: 225
    edited 2006-04-25 00:59
    Well, here was my attempt:

    The requirements were that the operator would see the 5 digit entry in realtime. The ability to verify the entry or delete it. The initial 5 X's were to show the operator it needed 5 digits and they disappear as the number is entered. At any entry step, the operator can only press keys related to that specific operation.

    The requirements for the·2 digit·number are the same.

    While the program is working fine, I will need to add a real time clock. As you can see there is not near enough room left for this. I could accept the default key press returns and free up some space.

    Some of the problems I have run into are: If I collect a set of 5 keypresses then pull the buffer, I couldn't find a way to display each key press in realtime on the LCD. Also if I setup a single keyfind as a GOSUB then I was never able to retain a complete 5 digit variable as it would only retun the last key press

    Bottom line is, there should only be one keyfind and that should be a GOSUB, the returns from each access need to be stored and displayed in realtime creating only one variable. Anyone have a good idea?



    Thanks
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-25 02:25
    Paul Baker said...
    Chris is talking about using a CASE statement, where only those conditions you specify are acted upon. If you post the code section dealing with handling keys we would be better equipped to offer advice.
    Thanks Paul.· Yes, the way you check the values and/or act upon them does depend greatly on the structure of your code.· In this case Paul has exactly the right suggestion.· My original message was directed at IF...THEN cases prior to knowing your existing code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-04-25 15:44
    Ok, first off the entire initization process past the setting of keypad row/ col can be boiled down into a single SEROUT 14, 396, [noparse][[/noparse]$0A, i, val], where i is a value iterated in a·FOR...NEXT loop and val is retrieved via a LOOKUP using i as the index value.

    Second, you have basically 2 types of keyfinds, you should create a subroutine for each using a variable inside it (like i since its always best to reuse temporary variables when possible) to distinguish the seperate calls (like you would declare keyval as an array, then use the index i as a pointer into that array for where to store the value, and when you do a SEROUT to the LCD you would send SEROUT 2,396,[noparse][[/noparse]182+i,keyval(i)]

    Then in your main execution you would use FOR...NEXT loops to set i to the appropriate value then call the subroutine.

    Following these techniques, you should be able to boil you program down to roughly 1/10th the current size, and any modifications that need to be made can be done once instead of in every keypress.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1+1=10
Sign In or Register to comment.