libreria teclado

Dependents:   Tarea3_Teclado Tarea3_Teclado_Mejoras Tarea3_Teclado_sonido IngresoHORA ... more

Fork of keypad by Leonardo Restrepo

Committer:
yoonghm
Date:
Mon Jan 30 09:41:47 2012 +0000
Revision:
0:2df66331c109
Child:
1:b5eee44fa8a2
Initial published version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yoonghm 0:2df66331c109 1 /* mbed Keypad library, using user-defined interrupt callback
yoonghm 0:2df66331c109 2 * Copyright (c) 2012 Yoong Hor Meng
yoonghm 0:2df66331c109 3 *
yoonghm 0:2df66331c109 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
yoonghm 0:2df66331c109 5 * of this software and associated documentation files (the "Software"), to deal
yoonghm 0:2df66331c109 6 * in the Software without restriction, including without limitation the rights
yoonghm 0:2df66331c109 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
yoonghm 0:2df66331c109 8 * copies of the Software, and to permit persons to whom the Software is
yoonghm 0:2df66331c109 9 * furnished to do so, subject to the following conditions:
yoonghm 0:2df66331c109 10 *
yoonghm 0:2df66331c109 11 * The above copyright notice and this permission notice shall be included in
yoonghm 0:2df66331c109 12 * all copies or substantial portions of the Software.
yoonghm 0:2df66331c109 13 *
yoonghm 0:2df66331c109 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
yoonghm 0:2df66331c109 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
yoonghm 0:2df66331c109 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
yoonghm 0:2df66331c109 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
yoonghm 0:2df66331c109 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
yoonghm 0:2df66331c109 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
yoonghm 0:2df66331c109 20 * THE SOFTWARE
yoonghm 0:2df66331c109 21 */
yoonghm 0:2df66331c109 22
yoonghm 0:2df66331c109 23 #ifndef KEYPAD_H
yoonghm 0:2df66331c109 24 #define KEYPAD_H
yoonghm 0:2df66331c109 25
yoonghm 0:2df66331c109 26 #include "mbed.h"
yoonghm 0:2df66331c109 27 #include "FPointer.h"
yoonghm 0:2df66331c109 28
yoonghm 0:2df66331c109 29 /**
yoonghm 0:2df66331c109 30 * An interrupt-based interface to 4x4 keypad.
yoonghm 0:2df66331c109 31 *
yoonghm 0:2df66331c109 32 * On each key pressed on a keypad, the index of the key is passed to a
yoonghm 0:2df66331c109 33 * user-defined function. User is free to define what to be done with the
yoonghm 0:2df66331c109 34 * input.
yoonghm 0:2df66331c109 35 *
yoonghm 0:2df66331c109 36 *
yoonghm 0:2df66331c109 37 * @code
yoonghm 0:2df66331c109 38 *
yoonghm 0:2df66331c109 39 * #include "mbed.h"
yoonghm 0:2df66331c109 40 * #include "keypad.h"
yoonghm 0:2df66331c109 41 *
yoonghm 0:2df66331c109 42 * // Define your own keypad values
yoonghm 0:2df66331c109 43 * char Keytable[] = { '1', '2', '3', 'A',
yoonghm 0:2df66331c109 44 * '4', '5', '6', 'B',
yoonghm 0:2df66331c109 45 * '7', '8', '9', 'C',
yoonghm 0:2df66331c109 46 * '*', '0', '#', 'D'
yoonghm 0:2df66331c109 47 * };
yoonghm 0:2df66331c109 48 *
yoonghm 0:2df66331c109 49 * uint32_t cbAfterInput(uint32_t index) {
yoonghm 0:2df66331c109 50 * printf("Index:%d => Key:%c\n", key, Keytable[index]);
yoonghm 0:2df66331c109 51 * return 0;
yoonghm 0:2df66331c109 52 * }
yoonghm 0:2df66331c109 53 *
yoonghm 0:2df66331c109 54 * int main() {
yoonghm 0:2df66331c109 55 * Keypad keypad(p25, p26, p27, p28, p21, p22, p23, p24);
yoonghm 0:2df66331c109 56 * keypad.CallAfterInput(&cbAfterInput);
yoonghm 0:2df66331c109 57 * keypad.Start();
yoonghm 0:2df66331c109 58 *
yoonghm 0:2df66331c109 59 * while (1) {
yoonghm 0:2df66331c109 60 * wait_ms(100);
yoonghm 0:2df66331c109 61 * }
yoonghm 0:2df66331c109 62 * }
yoonghm 0:2df66331c109 63 * @endcode
yoonghm 0:2df66331c109 64 */
yoonghm 0:2df66331c109 65 class Keypad {
yoonghm 0:2df66331c109 66 public:
yoonghm 0:2df66331c109 67 /** Create a Keypad interface
yoonghm 0:2df66331c109 68 *
yoonghm 0:2df66331c109 69 * @param row<3..0> Row data lines
yoonghm 0:2df66331c109 70 * @param col<3..0> Column data lines
yoonghm 0:2df66331c109 71 * @param debounce_ms Debounce in ms (Default to 20ms)
yoonghm 0:2df66331c109 72 */
yoonghm 0:2df66331c109 73 Keypad(PinName row3, PinName row2, PinName row1, PinName row0,
yoonghm 0:2df66331c109 74 PinName col3, PinName col2, PinName col1, PinName col0,
yoonghm 0:2df66331c109 75 int debounce_ms = 20);
yoonghm 0:2df66331c109 76
yoonghm 0:2df66331c109 77 /** Start the keypad interrupt routines
yoonghm 0:2df66331c109 78 */
yoonghm 0:2df66331c109 79 void Start(void);
yoonghm 0:2df66331c109 80
yoonghm 0:2df66331c109 81 /** Stop the keypad interrupt routines
yoonghm 0:2df66331c109 82 */
yoonghm 0:2df66331c109 83 void Stop(void);
yoonghm 0:2df66331c109 84
yoonghm 0:2df66331c109 85 /** User-defined function that to be called when a key is pressed
yoonghm 0:2df66331c109 86 * @param fptr A function pointer takes a uint32_t and
yoonghm 0:2df66331c109 87 * returns uint32_t
yoonghm 0:2df66331c109 88 */
yoonghm 0:2df66331c109 89 void CallAfterInput(uint32_t (*fptr)(uint32_t));
yoonghm 0:2df66331c109 90
yoonghm 0:2df66331c109 91 protected:
yoonghm 0:2df66331c109 92 InterruptIn _row0;
yoonghm 0:2df66331c109 93 InterruptIn _row1;
yoonghm 0:2df66331c109 94 InterruptIn _row2;
yoonghm 0:2df66331c109 95 InterruptIn _row3;
yoonghm 0:2df66331c109 96 BusOut _cols;
yoonghm 0:2df66331c109 97 int _debounce;
yoonghm 0:2df66331c109 98 FPointer _input; // Called after each input
yoonghm 0:2df66331c109 99
yoonghm 0:2df66331c109 100 void _callback(int row, InterruptIn &therow);
yoonghm 0:2df66331c109 101 void _cbRow0Rise(void);
yoonghm 0:2df66331c109 102 void _cbRow1Rise(void);
yoonghm 0:2df66331c109 103 void _cbRow2Rise(void);
yoonghm 0:2df66331c109 104 void _cbRow3Rise(void);
yoonghm 0:2df66331c109 105 void _setupRiseTrigger(void);
yoonghm 0:2df66331c109 106 void _dummy(void) { };
yoonghm 0:2df66331c109 107 };
yoonghm 0:2df66331c109 108
yoonghm 0:2df66331c109 109 #endif // KEYPAD_H