jdlfkjasdf

Dependents:   electrocoagulador_teclado

Committer:
rlanghbv
Date:
Sat Sep 19 19:54:18 2015 +0000
Revision:
19:0a2ec1b8bd5b
Parent:
18:a973524a445d
Child:
20:064b86485f26
Doc Update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rlanghbv 14:d6592dac4365 1 /*mbed simple keypad library, using polling
rlanghbv 1:fa689a04c361 2
rlanghbv 1:fa689a04c361 3 Copyright (c) 2015 Rune Langøy
DimiterK 0:1fa357ea3fcc 4
DimiterK 0:1fa357ea3fcc 5 Permission is hereby granted, free of charge, to any person obtaining a copy
DimiterK 0:1fa357ea3fcc 6 of this software and associated documentation files (the "Software"), to deal
DimiterK 0:1fa357ea3fcc 7 in the Software without restriction, including without limitation the rights
DimiterK 0:1fa357ea3fcc 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
DimiterK 0:1fa357ea3fcc 9 copies of the Software, and to permit persons to whom the Software is
DimiterK 0:1fa357ea3fcc 10 furnished to do so, subject to the following conditions:
DimiterK 0:1fa357ea3fcc 11
DimiterK 0:1fa357ea3fcc 12 The above copyright notice and this permission notice shall be included in
DimiterK 0:1fa357ea3fcc 13 all copies or substantial portions of the Software.
DimiterK 0:1fa357ea3fcc 14
DimiterK 0:1fa357ea3fcc 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
DimiterK 0:1fa357ea3fcc 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
DimiterK 0:1fa357ea3fcc 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
DimiterK 0:1fa357ea3fcc 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
DimiterK 0:1fa357ea3fcc 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
DimiterK 0:1fa357ea3fcc 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
DimiterK 0:1fa357ea3fcc 21 THE SOFTWARE.
DimiterK 0:1fa357ea3fcc 22 */
DimiterK 0:1fa357ea3fcc 23
DimiterK 0:1fa357ea3fcc 24 #ifndef KEYPAD_H
DimiterK 0:1fa357ea3fcc 25 #define KEYPAD_H
DimiterK 0:1fa357ea3fcc 26
DimiterK 0:1fa357ea3fcc 27 #include "DigitalIn.h"
DimiterK 0:1fa357ea3fcc 28 #include "BusOut.h"
DimiterK 0:1fa357ea3fcc 29
rlanghbv 14:d6592dac4365 30 namespace mbed
rlanghbv 14:d6592dac4365 31 {
DimiterK 0:1fa357ea3fcc 32
DimiterK 0:1fa357ea3fcc 33 const char NO_KEY = '\0';
DimiterK 0:1fa357ea3fcc 34 #define KEY_RELEASED NO_KEY
rlanghbv 14:d6592dac4365 35
rlanghbv 16:ea3c612999ac 36 /** @brief table showing the printed layout of the keypad \n
rlanghbv 16:ea3c612999ac 37 */
rlanghbv 1:fa689a04c361 38 const char keys[16] = {'1','2','3','A',
rlanghbv 14:d6592dac4365 39 '4','5','6','B',
rlanghbv 14:d6592dac4365 40 '7','8','9','C',
rlanghbv 14:d6592dac4365 41 '*','0','#','D'
rlanghbv 14:d6592dac4365 42 };
rlanghbv 14:d6592dac4365 43 /**
rlanghbv 14:d6592dac4365 44 * An simple polling-based interface to read a 4x4 keypad.
rlanghbv 14:d6592dac4365 45 *
rlanghbv 14:d6592dac4365 46 * The function getKey() reads the index of the pressed key
rlanghbv 14:d6592dac4365 47 * and returns the letter of the pressed key
rlanghbv 14:d6592dac4365 48 *
rlanghbv 14:d6592dac4365 49 * This work is a derivative of the works done by:
rlanghbv 14:d6592dac4365 50 * Dimiter Kentri in 2010 https://developer.mbed.org/users/DimiterK/code/keypad/
rlanghbv 14:d6592dac4365 51 * and
rlanghbv 14:d6592dac4365 52 * Yoong Hor Meng in 2012 https://developer.mbed.org/users/yoonghm/code/keypad/
rlanghbv 14:d6592dac4365 53 *
rlanghbv 14:d6592dac4365 54 * Example:
rlanghbv 14:d6592dac4365 55 * @code
rlanghbv 14:d6592dac4365 56 * #include "mbed.h"
rlanghbv 14:d6592dac4365 57 * #include "keypad.h"
rlanghbv 14:d6592dac4365 58 *
rlanghbv 14:d6592dac4365 59 * Serial pc(USBTX, USBRX);
rlanghbv 14:d6592dac4365 60 * Keypad keypad(D3,D4,D5,D6,D7,D8,D9,D10);
rlanghbv 14:d6592dac4365 61 * // Keypad keypad( PC_3,PC_2,PA_0,PA_1,PA_4,PB_0,PC_1,PC_0 ); // Tested on Nucleo303RE card
rlanghbv 14:d6592dac4365 62 *
rlanghbv 14:d6592dac4365 63 * int main(void)
rlanghbv 14:d6592dac4365 64 * {
rlanghbv 14:d6592dac4365 65 * keypad.enablePullUp();
rlanghbv 14:d6592dac4365 66 * char key;
rlanghbv 14:d6592dac4365 67 * pc.printf("Please touch a key on the keypad\r\n");
rlanghbv 14:d6592dac4365 68 * while(1)
rlanghbv 14:d6592dac4365 69 * {
rlanghbv 14:d6592dac4365 70 * key = keypad.getKey();
rlanghbv 14:d6592dac4365 71 * if(key != KEY_RELEASED)
rlanghbv 14:d6592dac4365 72 * {
rlanghbv 14:d6592dac4365 73 * pc.printf("%c\r\n",key);
rlanghbv 14:d6592dac4365 74 * wait(0.2);
rlanghbv 14:d6592dac4365 75 * }
rlanghbv 14:d6592dac4365 76 * }
rlanghbv 14:d6592dac4365 77 * }
rlanghbv 14:d6592dac4365 78 * @endcode
rlanghbv 1:fa689a04c361 79
rlanghbv 14:d6592dac4365 80 */
rlanghbv 14:d6592dac4365 81
rlanghbv 14:d6592dac4365 82 class Keypad
rlanghbv 14:d6592dac4365 83 {
rlanghbv 14:d6592dac4365 84 public:
rlanghbv 8:862b0a362754 85 /** @brief Create a 4x4 (col, row) or 4x4 keypad interface\n
rlanghbv 11:2176a5cf72b2 86 * <pre>
rlanghbv 3:d3772b2d763c 87 * | Col0 | Col1 | Col2 | Col3 \n
rlanghbv 3:d3772b2d763c 88 * -------+------+------+------+----- \n
rlanghbv 3:d3772b2d763c 89 * Row 0 | x | x | x | x \n
rlanghbv 3:d3772b2d763c 90 * Row 1 | x | x | x | x \n
rlanghbv 3:d3772b2d763c 91 * Row 2 | x | x | x | x \n
rlanghbv 3:d3772b2d763c 92 * Row 3 | x | x | x | x \n
rlanghbv 11:2176a5cf72b2 93 * </pre>
rlanghbv 6:d0a45d163653 94 *
rlanghbv 1:fa689a04c361 95 * @param col<0..3> Row data lines
rlanghbv 1:fa689a04c361 96 * @param row<0..3> Column data lines
rlanghbv 1:fa689a04c361 97 */
rlanghbv 14:d6592dac4365 98 Keypad(PinName col0, PinName col1, PinName col2, PinName col3, PinName row0,PinName row1, PinName row2, PinName row3);
rlanghbv 14:d6592dac4365 99
rlanghbv 14:d6592dac4365 100 /** @brief Returns the letter of the pressed key \n
rlanghbv 14:d6592dac4365 101 *
rlanghbv 16:ea3c612999ac 102 * @return char
rlanghbv 18:a973524a445d 103 * @returns
rlanghbv 19:0a2ec1b8bd5b 104 * The pressed character\n
rlanghbv 18:a973524a445d 105 * -1 if no keys was pressed
rlanghbv 14:d6592dac4365 106 */
rlanghbv 14:d6592dac4365 107 char getKey();
DimiterK 0:1fa357ea3fcc 108
rlanghbv 14:d6592dac4365 109 /** @brief Detects if any key was pressed
rlanghbv 14:d6592dac4365 110 *
rlanghbv 15:78f9c379a2e1 111 * @return bool
rlanghbv 15:78f9c379a2e1 112 * @retval true a key is pressed
rlanghbv 15:78f9c379a2e1 113 * @retval false no keys was not pressed
rlanghbv 14:d6592dac4365 114 */
rlanghbv 14:d6592dac4365 115 bool getKeyPressed();
rlanghbv 14:d6592dac4365 116 /** Enables internal PullUp resistors on the coloums pins
rlanghbv 14:d6592dac4365 117 *
rlanghbv 14:d6592dac4365 118 * @return void
rlanghbv 14:d6592dac4365 119 */
rlanghbv 14:d6592dac4365 120 void enablePullUp();
rlanghbv 14:d6592dac4365 121
rlanghbv 14:d6592dac4365 122 protected:
rlanghbv 14:d6592dac4365 123 BusIn _cols;
rlanghbv 14:d6592dac4365 124 BusOut _rows;
rlanghbv 19:0a2ec1b8bd5b 125 /** @brief return the index value
rlanghbv 14:d6592dac4365 126 * representating the pressed key \n
rlanghbv 14:d6592dac4365 127 *
rlanghbv 16:ea3c612999ac 128 * @return int
rlanghbv 19:0a2ec1b8bd5b 129 * @returns
rlanghbv 19:0a2ec1b8bd5b 130 * The index representing the pushed key used in table keys\n
rlanghbv 18:a973524a445d 131 * -1 if no key was pressed
rlanghbv 14:d6592dac4365 132 */
rlanghbv 14:d6592dac4365 133 int getKeyIndex();
rlanghbv 14:d6592dac4365 134
DimiterK 0:1fa357ea3fcc 135 };
DimiterK 0:1fa357ea3fcc 136
DimiterK 0:1fa357ea3fcc 137 }
DimiterK 0:1fa357ea3fcc 138 #endif