Initial key scan code |
This is the initial code for scanning the keyboard input, doing the column and row scanning to locate which point in the matrix has been pressed, and then using the kdata[][] multi-dimensional array to decode the row/column to the actual key located there. The code is using the primary UART on the Arduino to send which key has been pressed to the laptop that is attached to it with its serial terminal up. The debounce mechanism is a delay after a keypress is noted; This works in as much as if you type too fast, keys go missing, but it eliminates the repeated keypresses when you get a ring on keypress. |
Smarter keyscan code, with special keys, uppercase map and debounce |
This code is still a work in progress, but shows some marked improvements over the previous code. A bitmask of special keys is stored in a two-byte int, flags, to keep track of any key modifiers (Shift, et al). There are now three keymaps, kdata[][] which contains "lowercase" keys, udata[][] which contains the "uppercase" keys - including the characters you get when you hit the Shift key on numbers (1 -> !, 2 -> @, etc), and sdata[][] with the "Special" key map. "Special" keys are decoded first and stored in the bitmask, and then both the lower and upper case keys are stored for later output. The debounce logic is a little bit smarter, accumulating keys over time (so if you caught the end of a debounce and then the next key is pressed, it'll erase the previous key with the new one). The threshold is a little tighter, so it doesn't catch too many repeats, but if you type fast enough, it still eats characters. Certainly room for improvement. We also have rudimentary CapsLock support, but no indicator light yet. |