jdlfkjasdf

Dependents:   electrocoagulador_teclado

Committer:
rlanghbv
Date:
Sat Sep 19 18:45:01 2015 +0000
Revision:
16:ea3c612999ac
Parent:
15:78f9c379a2e1
Child:
17:f9b292067464
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 16:ea3c612999ac 103 * @retval -1 Error: no keys was pressed
rlanghbv 16:ea3c612999ac 104 * @retval The pressed character
rlanghbv 14:d6592dac4365 105 */
rlanghbv 14:d6592dac4365 106 char getKey();
DimiterK 0:1fa357ea3fcc 107
rlanghbv 14:d6592dac4365 108 /** @brief Detects if any key was pressed
rlanghbv 14:d6592dac4365 109 *
rlanghbv 15:78f9c379a2e1 110 * @return bool
rlanghbv 15:78f9c379a2e1 111 * @retval true a key is pressed
rlanghbv 15:78f9c379a2e1 112 * @retval false no keys was not pressed
rlanghbv 14:d6592dac4365 113 */
rlanghbv 14:d6592dac4365 114 bool getKeyPressed();
rlanghbv 14:d6592dac4365 115 /** Enables internal PullUp resistors on the coloums pins
rlanghbv 14:d6592dac4365 116 *
rlanghbv 14:d6592dac4365 117 * @return void
rlanghbv 14:d6592dac4365 118 */
rlanghbv 14:d6592dac4365 119 void enablePullUp();
rlanghbv 14:d6592dac4365 120
rlanghbv 14:d6592dac4365 121 protected:
rlanghbv 14:d6592dac4365 122 BusIn _cols;
rlanghbv 14:d6592dac4365 123 BusOut _rows;
rlanghbv 14:d6592dac4365 124 /** @brief return the index value \n
rlanghbv 14:d6592dac4365 125 * representating the pressed key \n
rlanghbv 14:d6592dac4365 126 * if no walid key was pressed \n
rlanghbv 14:d6592dac4365 127 * the value -1 is returned
rlanghbv 14:d6592dac4365 128 *
rlanghbv 16:ea3c612999ac 129 * @return int
rlanghbv 16:ea3c612999ac 130 * @retval The index representing the pushed key used in table keys
rlanghbv 14:d6592dac4365 131 */
rlanghbv 14:d6592dac4365 132 int getKeyIndex();
rlanghbv 14:d6592dac4365 133
DimiterK 0:1fa357ea3fcc 134 };
DimiterK 0:1fa357ea3fcc 135
DimiterK 0:1fa357ea3fcc 136 }
DimiterK 0:1fa357ea3fcc 137 #endif