driver to control n by m matrix keyboard with external pull-ups on columns
Dependents: LoopCounter HelloKeypad MultiKey EventKeypad ... more
Hotboards_keypad.h@0:4ca112f96484, 2016-02-09 (annotated)
- Committer:
- Hotboards
- Date:
- Tue Feb 09 03:25:28 2016 +0000
- Revision:
- 0:4ca112f96484
- Child:
- 2:e870110f753b
keyoad first release, is not tested
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Hotboards | 0:4ca112f96484 | 1 | /* |
Hotboards | 0:4ca112f96484 | 2 | || |
Hotboards | 0:4ca112f96484 | 3 | || @file Hotboards_Keypad.h |
Hotboards | 0:4ca112f96484 | 4 | || @version 3.2 |
Hotboards | 0:4ca112f96484 | 5 | || @ported by Diego (Hotboards) |
Hotboards | 0:4ca112f96484 | 6 | || This Keypad fork library allow to work with keyboard that |
Hotboards | 0:4ca112f96484 | 7 | || has physical pull-ups on columns (rather than rows) |
Hotboards | 0:4ca112f96484 | 8 | || |
Hotboards | 0:4ca112f96484 | 9 | || Keypad library originaly develop by: |
Hotboards | 0:4ca112f96484 | 10 | || @author Mark Stanley, Alexander Brevig |
Hotboards | 0:4ca112f96484 | 11 | || @contact mstanley@technologist.com, alexanderbrevig@gmail.com |
Hotboards | 0:4ca112f96484 | 12 | || |
Hotboards | 0:4ca112f96484 | 13 | || @description |
Hotboards | 0:4ca112f96484 | 14 | || | This library provides a simple interface for using matrix |
Hotboards | 0:4ca112f96484 | 15 | || | keypads. It supports multiple keypresses while maintaining |
Hotboards | 0:4ca112f96484 | 16 | || | backwards compatibility with the old single key library. |
Hotboards | 0:4ca112f96484 | 17 | || | It also supports user selectable pins and definable keymaps. |
Hotboards | 0:4ca112f96484 | 18 | || # |
Hotboards | 0:4ca112f96484 | 19 | || |
Hotboards | 0:4ca112f96484 | 20 | || @license |
Hotboards | 0:4ca112f96484 | 21 | || | This library is free software; you can redistribute it and/or |
Hotboards | 0:4ca112f96484 | 22 | || | modify it under the terms of the GNU Lesser General Public |
Hotboards | 0:4ca112f96484 | 23 | || | License as published by the Free Software Foundation; version |
Hotboards | 0:4ca112f96484 | 24 | || | 2.1 of the License. |
Hotboards | 0:4ca112f96484 | 25 | || | |
Hotboards | 0:4ca112f96484 | 26 | || | This library is distributed in the hope that it will be useful, |
Hotboards | 0:4ca112f96484 | 27 | || | but WITHOUT ANY WARRANTY; without even the implied warranty of |
Hotboards | 0:4ca112f96484 | 28 | || | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
Hotboards | 0:4ca112f96484 | 29 | || | Lesser General Public License for more details. |
Hotboards | 0:4ca112f96484 | 30 | || | |
Hotboards | 0:4ca112f96484 | 31 | || | You should have received a copy of the GNU Lesser General Public |
Hotboards | 0:4ca112f96484 | 32 | || | License along with this library; if not, write to the Free Software |
Hotboards | 0:4ca112f96484 | 33 | || | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Hotboards | 0:4ca112f96484 | 34 | || # |
Hotboards | 0:4ca112f96484 | 35 | || |
Hotboards | 0:4ca112f96484 | 36 | */ |
Hotboards | 0:4ca112f96484 | 37 | |
Hotboards | 0:4ca112f96484 | 38 | #ifndef KEYPAD_H |
Hotboards | 0:4ca112f96484 | 39 | #define KEYPAD_H |
Hotboards | 0:4ca112f96484 | 40 | |
Hotboards | 0:4ca112f96484 | 41 | #include "Key.h" |
Hotboards | 0:4ca112f96484 | 42 | |
Hotboards | 0:4ca112f96484 | 43 | |
Hotboards | 0:4ca112f96484 | 44 | #define OPEN 0 |
Hotboards | 0:4ca112f96484 | 45 | #define CLOSED 1 |
Hotboards | 0:4ca112f96484 | 46 | |
Hotboards | 0:4ca112f96484 | 47 | typedef char KeypadEvent; |
Hotboards | 0:4ca112f96484 | 48 | typedef unsigned int uint; |
Hotboards | 0:4ca112f96484 | 49 | typedef unsigned long ulong; |
Hotboards | 0:4ca112f96484 | 50 | |
Hotboards | 0:4ca112f96484 | 51 | // Made changes according to this post http://arduino.cc/forum/index.php?topic=58337.0 |
Hotboards | 0:4ca112f96484 | 52 | // by Nick Gammon. Thanks for the input Nick. It actually saved 78 bytes for me. :) |
Hotboards | 0:4ca112f96484 | 53 | typedef struct { |
Hotboards | 0:4ca112f96484 | 54 | uint8_t rows; |
Hotboards | 0:4ca112f96484 | 55 | uint8_t columns; |
Hotboards | 0:4ca112f96484 | 56 | } KeypadSize; |
Hotboards | 0:4ca112f96484 | 57 | |
Hotboards | 0:4ca112f96484 | 58 | #define LIST_MAX 10 // Max number of keys on the active list. |
Hotboards | 0:4ca112f96484 | 59 | #define MAPSIZE 10 // MAPSIZE is the number of rows (times 16 columns) |
Hotboards | 0:4ca112f96484 | 60 | #define makeKeymap(x) ((char*)x) |
Hotboards | 0:4ca112f96484 | 61 | |
Hotboards | 0:4ca112f96484 | 62 | |
Hotboards | 0:4ca112f96484 | 63 | //class Keypad : public Key, public HAL_obj { |
Hotboards | 0:4ca112f96484 | 64 | class Keypad : public Key { |
Hotboards | 0:4ca112f96484 | 65 | public: |
Hotboards | 0:4ca112f96484 | 66 | |
Hotboards | 0:4ca112f96484 | 67 | Keypad(char *userKeymap, DigitalInOut *row, DigitalInOut *col, uint8_t numRows, uint8_t numCols); |
Hotboards | 0:4ca112f96484 | 68 | |
Hotboards | 0:4ca112f96484 | 69 | uint bitMap[MAPSIZE]; // 10 row x 16 column array of bits. Except Due which has 32 columns. |
Hotboards | 0:4ca112f96484 | 70 | Key key[LIST_MAX]; |
Hotboards | 0:4ca112f96484 | 71 | unsigned long holdTimer; |
Hotboards | 0:4ca112f96484 | 72 | |
Hotboards | 0:4ca112f96484 | 73 | char getKey(); |
Hotboards | 0:4ca112f96484 | 74 | bool getKeys(); |
Hotboards | 0:4ca112f96484 | 75 | KeyState getState(); |
Hotboards | 0:4ca112f96484 | 76 | void begin(char *userKeymap); |
Hotboards | 0:4ca112f96484 | 77 | bool isPressed(char keyChar); |
Hotboards | 0:4ca112f96484 | 78 | void setDebounceTime(uint); |
Hotboards | 0:4ca112f96484 | 79 | void setHoldTime(uint); |
Hotboards | 0:4ca112f96484 | 80 | void addEventListener(void (*listener)(char)); |
Hotboards | 0:4ca112f96484 | 81 | int findInList(char keyChar); |
Hotboards | 0:4ca112f96484 | 82 | int findInList(int keyCode); |
Hotboards | 0:4ca112f96484 | 83 | char waitForKey(); |
Hotboards | 0:4ca112f96484 | 84 | bool keyStateChanged(); |
Hotboards | 0:4ca112f96484 | 85 | uint8_t numKeys(); |
Hotboards | 0:4ca112f96484 | 86 | |
Hotboards | 0:4ca112f96484 | 87 | private: |
Hotboards | 0:4ca112f96484 | 88 | unsigned long startTime; |
Hotboards | 0:4ca112f96484 | 89 | char *keymap; |
Hotboards | 0:4ca112f96484 | 90 | DigitalInOut *rowPins; |
Hotboards | 0:4ca112f96484 | 91 | DigitalInOut *columnPins; |
Hotboards | 0:4ca112f96484 | 92 | KeypadSize sizeKpd; |
Hotboards | 0:4ca112f96484 | 93 | uint debounceTime; |
Hotboards | 0:4ca112f96484 | 94 | uint holdTime; |
Hotboards | 0:4ca112f96484 | 95 | bool single_key; |
Hotboards | 0:4ca112f96484 | 96 | Timer debounce; |
Hotboards | 0:4ca112f96484 | 97 | |
Hotboards | 0:4ca112f96484 | 98 | void scanKeys(); |
Hotboards | 0:4ca112f96484 | 99 | bool updateList(); |
Hotboards | 0:4ca112f96484 | 100 | void nextKeyState(uint8_t n, bool button); |
Hotboards | 0:4ca112f96484 | 101 | void transitionTo(uint8_t n, KeyState nextState); |
Hotboards | 0:4ca112f96484 | 102 | void (*keypadEventListener)(char); |
Hotboards | 0:4ca112f96484 | 103 | }; |
Hotboards | 0:4ca112f96484 | 104 | |
Hotboards | 0:4ca112f96484 | 105 | #endif |
Hotboards | 0:4ca112f96484 | 106 | |
Hotboards | 0:4ca112f96484 | 107 | /* |
Hotboards | 0:4ca112f96484 | 108 | || @changelog |
Hotboards | 0:4ca112f96484 | 109 | || | 3.1 2013-01-15 - Mark Stanley : Fixed missing RELEASED & IDLE status when using a single key. |
Hotboards | 0:4ca112f96484 | 110 | || | 3.0 2012-07-12 - Mark Stanley : Made library multi-keypress by default. (Backwards compatible) |
Hotboards | 0:4ca112f96484 | 111 | || | 3.0 2012-07-12 - Mark Stanley : Modified pin functions to support Keypad_I2C |
Hotboards | 0:4ca112f96484 | 112 | || | 3.0 2012-07-12 - Stanley & Young : Removed static variables. Fix for multiple keypad objects. |
Hotboards | 0:4ca112f96484 | 113 | || | 3.0 2012-07-12 - Mark Stanley : Fixed bug that caused shorted pins when pressing multiple keys. |
Hotboards | 0:4ca112f96484 | 114 | || | 2.0 2011-12-29 - Mark Stanley : Added waitForKey(). |
Hotboards | 0:4ca112f96484 | 115 | || | 2.0 2011-12-23 - Mark Stanley : Added the public function keyStateChanged(). |
Hotboards | 0:4ca112f96484 | 116 | || | 2.0 2011-12-23 - Mark Stanley : Added the private function scanKeys(). |
Hotboards | 0:4ca112f96484 | 117 | || | 2.0 2011-12-23 - Mark Stanley : Moved the Finite State Machine into the function getKeyState(). |
Hotboards | 0:4ca112f96484 | 118 | || | 2.0 2011-12-23 - Mark Stanley : Removed the member variable lastUdate. Not needed after rewrite. |
Hotboards | 0:4ca112f96484 | 119 | || | 1.8 2011-11-21 - Mark Stanley : Added test to determine which header file to compile, |
Hotboards | 0:4ca112f96484 | 120 | || | WProgram.h or Arduino.h. |
Hotboards | 0:4ca112f96484 | 121 | || | 1.8 2009-07-08 - Alexander Brevig : No longer uses arrays |
Hotboards | 0:4ca112f96484 | 122 | || | 1.7 2009-06-18 - Alexander Brevig : This library is a Finite State Machine every time a state changes |
Hotboards | 0:4ca112f96484 | 123 | || | the keypadEventListener will trigger, if set |
Hotboards | 0:4ca112f96484 | 124 | || | 1.7 2009-06-18 - Alexander Brevig : Added setDebounceTime setHoldTime specifies the amount of |
Hotboards | 0:4ca112f96484 | 125 | || | microseconds before a HOLD state triggers |
Hotboards | 0:4ca112f96484 | 126 | || | 1.7 2009-06-18 - Alexander Brevig : Added transitionTo |
Hotboards | 0:4ca112f96484 | 127 | || | 1.6 2009-06-15 - Alexander Brevig : Added getState() and state variable |
Hotboards | 0:4ca112f96484 | 128 | || | 1.5 2009-05-19 - Alexander Brevig : Added setHoldTime() |
Hotboards | 0:4ca112f96484 | 129 | || | 1.4 2009-05-15 - Alexander Brevig : Added addEventListener |
Hotboards | 0:4ca112f96484 | 130 | || | 1.3 2009-05-12 - Alexander Brevig : Added lastUdate, in order to do simple debouncing |
Hotboards | 0:4ca112f96484 | 131 | || | 1.2 2009-05-09 - Alexander Brevig : Changed getKey() |
Hotboards | 0:4ca112f96484 | 132 | || | 1.1 2009-04-28 - Alexander Brevig : Modified API, and made variables private |
Hotboards | 0:4ca112f96484 | 133 | || | 1.0 2007-XX-XX - Mark Stanley : Initial Release |
Hotboards | 0:4ca112f96484 | 134 | || # |
Hotboards | 0:4ca112f96484 | 135 | */ |