multiple keys
Dependencies: Hotboards_keypad mbed
main.cpp@0:aecea5ee7e68, 2016-03-08 (annotated)
- Committer:
- RomanValenciaP
- Date:
- Tue Mar 08 19:31:58 2016 +0000
- Revision:
- 0:aecea5ee7e68
- Child:
- 1:2ca8747d39ed
beta release - needs testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RomanValenciaP | 0:aecea5ee7e68 | 1 | |
RomanValenciaP | 0:aecea5ee7e68 | 2 | #include "mbed.h" |
RomanValenciaP | 0:aecea5ee7e68 | 3 | #include "Hotboards_keypad.h" |
RomanValenciaP | 0:aecea5ee7e68 | 4 | #include <string> |
RomanValenciaP | 0:aecea5ee7e68 | 5 | |
RomanValenciaP | 0:aecea5ee7e68 | 6 | using std::string; |
RomanValenciaP | 0:aecea5ee7e68 | 7 | |
RomanValenciaP | 0:aecea5ee7e68 | 8 | char keys[ 4 ][ 4 ] = |
RomanValenciaP | 0:aecea5ee7e68 | 9 | { |
RomanValenciaP | 0:aecea5ee7e68 | 10 | { '1' , '2' , '3' , 'A' }, |
RomanValenciaP | 0:aecea5ee7e68 | 11 | { '4' , '5' , '6' , 'B' }, |
RomanValenciaP | 0:aecea5ee7e68 | 12 | { '7' , '8' , '9' , 'C' }, |
RomanValenciaP | 0:aecea5ee7e68 | 13 | { '*' , '0' , '#' , 'D' } |
RomanValenciaP | 0:aecea5ee7e68 | 14 | }; |
RomanValenciaP | 0:aecea5ee7e68 | 15 | |
RomanValenciaP | 0:aecea5ee7e68 | 16 | DigitalInOut rowPins[ 4 ] = { PA_6 , PA_7 , PB_6 , PC_7 }; |
RomanValenciaP | 0:aecea5ee7e68 | 17 | DigitalInOut colPins[ 4 ] = { PA_8 , PB_10 , PB_4 , PB_5 }; |
RomanValenciaP | 0:aecea5ee7e68 | 18 | |
RomanValenciaP | 0:aecea5ee7e68 | 19 | Keypad kpd( makeKeymap( keys ) , rowPins , colPins , 4 , 4 ); |
RomanValenciaP | 0:aecea5ee7e68 | 20 | |
RomanValenciaP | 0:aecea5ee7e68 | 21 | Serial pc( USBTX , USBRX ); |
RomanValenciaP | 0:aecea5ee7e68 | 22 | |
RomanValenciaP | 0:aecea5ee7e68 | 23 | int i; |
RomanValenciaP | 0:aecea5ee7e68 | 24 | |
RomanValenciaP | 0:aecea5ee7e68 | 25 | int main() |
RomanValenciaP | 0:aecea5ee7e68 | 26 | { |
RomanValenciaP | 0:aecea5ee7e68 | 27 | string msg; |
RomanValenciaP | 0:aecea5ee7e68 | 28 | while(1) |
RomanValenciaP | 0:aecea5ee7e68 | 29 | { |
RomanValenciaP | 0:aecea5ee7e68 | 30 | if( kpd.getKeys( ) ) |
RomanValenciaP | 0:aecea5ee7e68 | 31 | { |
RomanValenciaP | 0:aecea5ee7e68 | 32 | for( i = 0 ; i <= LIST_MAX ; i++ ) |
RomanValenciaP | 0:aecea5ee7e68 | 33 | { |
RomanValenciaP | 0:aecea5ee7e68 | 34 | if( kpd.key[ i ].stateChanged ) |
RomanValenciaP | 0:aecea5ee7e68 | 35 | { |
RomanValenciaP | 0:aecea5ee7e68 | 36 | switch( kpd.key[ i ].kstate ) |
RomanValenciaP | 0:aecea5ee7e68 | 37 | { |
RomanValenciaP | 0:aecea5ee7e68 | 38 | case PRESSED: |
RomanValenciaP | 0:aecea5ee7e68 | 39 | msg = " PRESSED. "; |
RomanValenciaP | 0:aecea5ee7e68 | 40 | break; |
RomanValenciaP | 0:aecea5ee7e68 | 41 | case HOLD: |
RomanValenciaP | 0:aecea5ee7e68 | 42 | msg = " HOLD. "; |
RomanValenciaP | 0:aecea5ee7e68 | 43 | break; |
RomanValenciaP | 0:aecea5ee7e68 | 44 | case RELEASED: |
RomanValenciaP | 0:aecea5ee7e68 | 45 | msg = " RELEASED. "; |
RomanValenciaP | 0:aecea5ee7e68 | 46 | break; |
RomanValenciaP | 0:aecea5ee7e68 | 47 | case IDLE: |
RomanValenciaP | 0:aecea5ee7e68 | 48 | msg = " IDLE. "; |
RomanValenciaP | 0:aecea5ee7e68 | 49 | break; |
RomanValenciaP | 0:aecea5ee7e68 | 50 | default: |
RomanValenciaP | 0:aecea5ee7e68 | 51 | break; |
RomanValenciaP | 0:aecea5ee7e68 | 52 | } |
RomanValenciaP | 0:aecea5ee7e68 | 53 | pc.printf( "Key " ); |
RomanValenciaP | 0:aecea5ee7e68 | 54 | pc.printf( "%c" , kpd.key[ i ].kchar ); |
RomanValenciaP | 0:aecea5ee7e68 | 55 | pc.printf( "%s" , msg.c_str() ); |
RomanValenciaP | 0:aecea5ee7e68 | 56 | pc.printf( "\n\r" ); |
RomanValenciaP | 0:aecea5ee7e68 | 57 | } |
RomanValenciaP | 0:aecea5ee7e68 | 58 | } |
RomanValenciaP | 0:aecea5ee7e68 | 59 | } |
RomanValenciaP | 0:aecea5ee7e68 | 60 | } |
RomanValenciaP | 0:aecea5ee7e68 | 61 | } |