{{ 5x5 Keypad Reader PST.spin Returns the entire 5x5 keypad matrix into a single LONG variable indicating which buttons are pressed. }} CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ text : "Parallax Serial Terminal" KP : "5x5 Keypad Reader" time : "Timing" VAR long keypad byte index PUB start ' Start PST text.start(115200) text.str(string(13,"5x5 Keypad Demo")) text.position(1, 7) text.str(string(13,"RAW keypad value 'long' 25 bits")) repeat keypad := KP.ReadKeyPad '<-- One line command to read the 5x5 keypad text.position(5, 9) text.bin(keypad, 25) 'Display RAW keypad value text.position(5, 10) text.str(decode(keypad)) time.pause(150) PUB decode(keybits): key key := -1 index := 0 repeat 25 if (keybits & (|< index))>>index == 1 key := lookup(index+1: string(13, "Clear"), string(13, "Left "), string(13, "Up "), string(13, "Down "), string(13, "Right"){ }, string(13, "Del "), string(13, "A + "), string(13, "B - "), string(13, "C X "), string(13, "D / "){ }, string(13, "^ "), string(13, "3 "), string(13, "6 "), string(13, "9 "), string(13, "# (-)"){ }, string(13, "Menu "), string(13, "2 "), string(13, "5 "), string(13, "8 "), string(13, "0 "){ }, string(13, "Enter"), string(13, "1 "), string(13, "4 "), string(13, "7 "), string(13, "* . ") ) index++ if key == -1 key := string(13, " ") DAT {{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ TERMS OF USE: MIT License │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │ │files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │ │modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│ │is furnished to do so, subject to the following conditions: │ │ │ │The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│ │ │ │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │ │WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │ │COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ │ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ }}