Shop OBEX P1 Docs P2 Docs Learn Events
Memkey Input — Parallax Forums

Memkey Input

blacksheep45blacksheep45 Posts: 41
edited 2008-11-12 05:12 in BASIC Stamp
Hi,
I am·currently writing a program using a bs2p40·that allows me to input 2 numbers using a memkey and a 4*4 keypad matrix·and then·add them together·and display the output on·an lcd output.
However since i am using a loop to do this, once the first number has been entered ie 123·only the last digit is recognized ie 3.

I was wondering if anyone would be able to help me solve this problem?

Kind Regards


Shaun

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-11-10 17:14
    You do not have your program attached to see how you are handling the input. It also matters whether you are sending back a raw binary number value or an ASCII representation of one. There are operators for dealing with this, but we don’t know what you have so far.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • blacksheep45blacksheep45 Posts: 41
    edited 2008-11-10 17:37
    Sorry Chris,

    Here is the code that i have got so far.
    Hope this helps


    Shaun
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-11-10 17:49
    Okay, so right in your GetKey routine you are doing ASCII translation to the key values as they come back. This is fine if all you’re doing is displaying the numbers, but since you need to work on values it seems like a better idea to deal with the raw values and only reformat for the display.

    In any event, the MemKey is only going to send one value per keypress. If you want to convert three entries (say 123) into a single number, then you’ll have to drop them into an array and their values weighted by position, to your target variable.

    So if you wanted to add 123 + 321 = 444, you could start adding values to an array until an arithmetic function key is pressed such as the + key. As soon as that happens your routine converts the 1, 2 and 3 by:

    Value = index(0) * 100
    Value = Value + index(1) * 10
    Value = Value + index(2)

    At this point you could start receiving new characters to be handled until the next function key is pressed such as =. In any event, the example above is set up for simplicity. In reality you would have to know the maximum value you want to deal with (say 255 or 65535), set up an appropriate array, and populate it in reverse so it calculates correctly regardless of how many digits were entered.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-10 17:51
    Your code logic is very convoluted with GOSUBs where GOTOs might be better and the GOTOs overlap and there's jumping into and out of a loop, etc. I don't see any place where you're treating characters as anything but isolated individual characters. Assuming you clean this logic up, the general way to handle numbers is:

    1) You have a working accumulator for the number, declared as a word. Say it's called NUMBER and is initialized to zero.

    2) If the input character (called CHAR) is greater or equal to "0" and less than or equal to "9", do: NUMBER = NUMBER * 10 + (CHAR - "0")

    3) If the input character is anything else, you now have a complete numeric value in NUMBER. Copy it wherever you need it and set NUMBER to zero again, then either ignore CHAR or interpret it depending on the needs of your program.

    Go through the above logic by hand with the input characters: "1", "2", "3", "A", "4", "5", "6", "B" (where "A" and "B" are in the extra column of the 4 x 4 keypad)
  • $WMc%$WMc% Posts: 1,884
    edited 2008-11-12 05:12
    blacksheep45

    · I got Your PM here Is a rough darft from some old stuff I did w/ a Menu....The MEMKey key presses will need to be converterd. I think I have all the parm. set for the BS2p40,,,Its just a Rough darft. But I think it'll give You the Gen. Idea
Sign In or Register to comment.