Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Hotboards_keypad mbed
main.cpp
00001 00002 #include "mbed.h" 00003 #include "Hotboards_keypad.h" 00004 00005 // Se define el arreglo keys con su respectivo número de renglones 00006 // y columnas, y con el valor de cada una de las teclas 00007 char keys[ 4 ][ 4 ] = 00008 { 00009 { '1' , '2' , '3' , 'A' }, 00010 { '4' , '5' , '6' , 'B' }, 00011 { '7' , '8' , '9' , 'C' }, 00012 { '*' , '0' , '#' , 'D' } 00013 }; 00014 00015 // Se definen los pines que conectan a las filas 00016 DigitalInOut rowPins[ 4 ] = { PA_6 , PA_7 , PB_6 , PC_7 }; 00017 // Se definen los pines que conectan a las columnas 00018 DigitalInOut colPins[ 4 ] = { PA_8 , PB_10 , PB_4 , PB_5 }; 00019 00020 // Se crea un nuevo teclado con los valores anteriores 00021 Keypad kpd( makeKeymap( keys ) , rowPins , colPins , 4 , 4 ); 00022 00023 // Se configura el puerto serial 00024 Serial pc( USBTX , USBRX ); 00025 00026 00027 // Esta función se manda a llamar dentro de la función getKey 00028 // cuando una tecla cambia su estado. 00029 void kpdEvent( KeypadEvent key ) 00030 { 00031 // Se pide el estado de la tecla activa 00032 switch( kpd.getState( ) ) 00033 { 00034 case PRESSED: // Se presionó 00035 pc.printf( "%c\t" , key ); 00036 pc.printf( "PRESSED\n\r" ); 00037 break; 00038 case RELEASED: // Se soltó 00039 pc.printf( "%c\t" , key ); 00040 pc.printf( "RELEASED\n\r" ); 00041 break; 00042 case HOLD: // Está presionada 00043 pc.printf( "%c\t" , key ); 00044 pc.printf( "HOLD\n\r" ); 00045 break; 00046 } 00047 } 00048 00049 int main() 00050 { 00051 // Se agrega la función kpdEvent como evento 00052 kpd.addEventListener( kpdEvent ); 00053 while(1) 00054 { 00055 // Se consulta constantemente para revisar si se presionó 00056 // una tecla o cambió su estado, esto es necesario para que se 00057 // llame a la función kdpEvent 00058 kpd.getKey( ); 00059 } 00060 }
Generated on Wed Jul 13 2022 19:37:06 by
1.7.2