A keypad is a simple method of entering data into an MMBasic based system. MMBasic supports either a 4×3 keypad or a 4×4 keypad and the monitoring and decoding of key presses is done in the background. When a key press is detected an interrupt will be issued where the program can deal with it.
To enable the keypad feature you use the command:
KEYPAD var, int, r1, r2, r3, r4, c1, c2, c3, c4
Where var is a variable that will be updated with the key code and int is the label of the interrupt to call when a new key press has been detected. r1, r2, r3 and r4 are the pin numbers used for the four row connections to the keypad.
Note that these must be pulled up to 3.3V by individual 10K resistors (see the diagram above). c1, c2, c3 and c4 are the column connections. c4 is only used with 4×4 keypads and should be omitted if you are using a 4×3 keypad.
Any I/O pins can be used and you do not have to set them up beforehand, the KEYPAD command will automatically do that for you.
The detection and decoding of key presses is done in the background and the program will continue after this command without interruption. When a key press is detected the value of the variable var will be set to the number representing the key (this is the number inside the circles in the diagram above). Then the interrupt will be called.
For example:
1 2 3 4 5 6 7 8 9 |
Keypad KeyCode, KP_Int, 2, 3, 4, 5, 21, 22, 23 ' 4x3 keyboard DO < body of the program > LOOP KP_Int: ' a key press has been detected PRINT "Key press = " KeyCode IRETURN |
Leave a Reply