Roman Valencia / Mbed 2 deprecated Nucleo_KEYPAD_2a

Dependencies:   Hotboards_keypad mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 #include "mbed.h"
00003 #include "Hotboards_keypad.h"
00004 #include <string>
00005 
00006 using std::string;
00007 
00008 // Se define el arreglo keys con su respectivo número de renglones
00009 // y columnas, y con el valor de cada una de las teclas
00010 char keys[ 4 ][ 4 ] =
00011 {
00012     { '1' , '2' , '3' , 'A' },
00013     { '4' , '5' , '6' , 'B' },
00014     { '7' , '8' , '9' , 'C' },
00015     { '*' , '0' , '#' , 'D' }
00016 };
00017 
00018 // Se definen los pines que conectan a las filas
00019 DigitalInOut rowPins[ 4 ] = { PA_6 , PA_7 , PB_6 , PC_7 };
00020 // Se definen los pines que conectan a las columnas
00021 DigitalInOut colPins[ 4 ] = { PA_8 , PB_10 , PB_4 , PB_5 };
00022 
00023 // Se crea un nuevo teclado con los valores anteriores
00024 Keypad kpd( makeKeymap( keys ) , rowPins , colPins , 4 , 4 );
00025 
00026 // Se configura el puerto serial
00027 Serial pc( USBTX , USBRX );
00028 
00029 int i;
00030 
00031 int main()
00032 {
00033     string msg;
00034     while(1)
00035     {
00036         // Se llenará el arreglo kpd.key[ ] con las teclas que se presionen,
00037         // y además regresará un (1) si se presionó una o mas teclas.
00038         if( kpd.getKeys( ) )
00039         {
00040             // Se revisa la lista de teclas
00041             for( i = 0 ; i <= LIST_MAX ; i++ )
00042             {
00043                 //Se revisa si alguna tecla cambio su estado
00044                 if( kpd.key[ i ].stateChanged )
00045                 {
00046                     // Se reporta el estado de la tecla activa:
00047                     // IDLE, PRESSED, HOLD, o RELEASED
00048                     switch( kpd.key[ i ].kstate )
00049                     {
00050                         case PRESSED:
00051                             msg = " PRESSED. "; // Se presionó
00052                             break;
00053                         case HOLD:              // Está presionada
00054                             msg = " HOLD. ";
00055                             break;
00056                         case RELEASED:          // Se soltó
00057                             msg = " RELEASED. ";
00058                             break;
00059                         case IDLE:
00060                             msg = " IDLE. ";
00061                             break;
00062                         default:
00063                             break;
00064                     }
00065                     // Se manda por serial el estado de la tecla presionada
00066                     pc.printf( "Key " );
00067                     pc.printf( "%c" , kpd.key[ i ].kchar );
00068                     pc.printf( "%s" , msg.c_str() );
00069                     pc.printf( "\n\r" );
00070                 }
00071             }
00072         }
00073     }
00074 }