Memkey Input
blacksheep45
Posts: 41
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
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 Savage
Parallax Engineering
Here is the code that i have got so far.
Hope this helps
Shaun
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
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)
· 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