programming the basic stamp with keypad to be able to read and write 00-99
paulval
Posts: 13
I am quite new at programming and I am using the program for the keypad. The program only reads 0-9 and a-d and i want to be able to read and write 00-99 a 2 digit number.
any help will be appreciated.
Thank You,
Paul
any help will be appreciated.
Thank You,
Paul
Comments
Please link to the code you're referring to, attach it, or post it in code tags so others can see what you're referring to. Also you should link the keypad being used as well.
I apologize since I am very new but I will be getting better as I use this web-site an well as learning programming.
Thank You,
Paul A. Valdez
I have no BS2 to try, and also not much expirience with the BasicStamp, but here is a code-fragment that should build a 2 digit dec from two keypresses.
If I understand the ReadKeypad subroutine right it returns a 16bit value where each bit stands for a pressed key.
The GetDecKey subroutine waits until all keys are released and then a new key is pressed. Then the key value is decoded:
With NCD keypad you get a number 1..16 for the key, and the LOOKUP reads the corresponding dec value for the key from a table (0..9).
Andy
I still can't put the code on this forum. The code I am trying to modify is the demo given for the keypad on your web site. Please help me.
Thank You,
Paul
Type (code) on the line before you code and (/code) on the line below it. Use [] instead of the () I used.
Did Ariba's example not work for you? It looks like it should at first glance. You need only add the existing keypad read subroutine and necessary variable declarations as he suggested.
' Display buttons pressed on the 4x4 Matrix Membrane Keypad
' Author: Parallax HK Engineering
' +---+---+---+---+
' P0 --X--X--X--X | 1 | 2 | 3 | A |
' | | | | +---+---+---+---+
' P1 --X--X--X--X | 4 | 5 | 6 | B |
' | | | | +---+---+---+---+
' P2 --X--X--X--X | 7 | 8 | 9 | C |
' | | | | +---+---+---+---+
' P3 --X--X--X--X | * | 0 | # | D |
' | | | | +---+---+---+---+
' R R R R <
4x1k resistors
' | | | |
' P4 P5 P6 P7
'
' {$STAMP BS2}
' {$PBASIC 2.5} '
[ Subroutine - ReadKeypad ]
' '
[ Subroutine - Update ]
'
[ Subroutine - Display ]
Paul
I got my hardware assembled and code started and ran out of time. What I will be posting today doesn't use the example code at all. I actually decided against that the moment I looked at it.
Thanks
Attached is a simple program to do what you asked. Please note the schematic in the comments is different than the example code you have. I didn't write the original example and felt it was overly complex and wasted resources. The attached example uses the same I/O pin connections, except that there are 4 x 10K pull-down resistors instead of the 4 x 1K inline resistors. It is important to make these connections properly. My code uses a traditional row/column bit-scan and adds an offset to the key value until a key has been found. This value is the translated through the LOOKUP command to return the value of the key (or ASCII value in the case of the non-numeric keys). This example does not handle timeouts on the input, has minimal error checking and is hard-coded to a single key value or a 2-digit number (see comments in code). Note that the reason it took me so long today was I was playing around with using the * key as a backspace key, the C to clear the entry and the # to terminate input for up to a 5-digit number. In this case though I decided to stick to what you were trying to do since I didn't think you would be able to modify the full version. I hope this helps. I finished it during my lunch break. :cool:
Your program worked. But how can I assign each value from 00 to 99 a different variable for instance 00 apples, 01 screws etc.
Thank You,
Paul
You wouldn't assign each number to a variable. The number is returned in a variable already and you just need to say:
IF num = 1 THEN
IF num = 2 THEN
etc.
Depending on how many values you use there are other ways to do this. You'll also be limited by the memory of the BASIC Stamp as to how many words you can put into memory. If you need more you'll need a different model of BS2 or an external EEPROM to hold the data.
Thank You,
Paul
Did you get the Private Message I sent you? As for where to check the characters, the main loop calls a subroutine to get the value of the number you type in. When it returns the variable specified contains that number. It is then displayed on the LCD. However you could instead have it print different messages based on the value. My example was designed to show you how to get a 2-digit value back from the keypad the way I felt the example code should have worked.
I'm pavan aditya
I'm trying to take up small module which displays the required text on the LCD when entered the repective code on the numeric pad.........
If you dont mind can you assist me with a helpful code for it......please.....
You will get better results by asking your question in one place rather than duplicating it in private conversations. It helps for you to specify what LCD and keypad you're using and whether you're using a Basic
Stamp or Propeller for a controller. An example of what output you want to see on the LCD for a key or keys on the keypad would also help.