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 // Defines the keys array with it's respective number of rows & cols, 00006 // and with the value of each key 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 // Defines the pins connected to the rows 00016 DigitalInOut rowPins[ 4 ] = { PA_6 , PA_7 , PB_6 , PC_7 }; 00017 // Defines the pins connected to the cols 00018 DigitalInOut colPins[ 4 ] = { PA_8 , PB_10 , PB_4 , PB_5 }; 00019 00020 // Creates a new keyboard with the values entered before 00021 Keypad kpd( makeKeymap( keys ) , rowPins , colPins , 4 , 4 ); 00022 00023 // Configures the serial port 00024 Serial pc( USBTX , USBRX ); 00025 00026 // 00027 int loopCount = 0; 00028 int timer_t = 0; 00029 00030 // Configures a timer 00031 Timer t; 00032 00033 int main() 00034 { 00035 // Starts the timer 00036 t.start( ); 00037 pc.printf( "Press any key: "); 00038 00039 00040 // Try playing with different debounceTime settings to see how it affects 00041 // the number of times per second your loop will run. The library prevents 00042 // setting it to anything below 1 millisecond. 00043 kpd.setDebounceTime ( 100 ); // setDebouncetime( ms ); 00044 while(1) 00045 { 00046 // Poll the keypad to look for any activation 00047 char key = kpd.getKey( ); 00048 00049 // Reports the number of times through the loop in 1 second. This will give 00050 // you a relative idea of just how much the debounceTime has changed the 00051 // speed of your code. If you set a high debounceTime your loopCount will 00052 // look good but your keypresses will start to feel sluggish. 00053 if(( t.read_ms( ) - timer_t ) > 1000 ) 00054 { 00055 pc.printf( "Your loop code ran " ); 00056 pc.printf( "%d" , loopCount ); 00057 pc.printf( " times over the last second" ); 00058 loopCount = 0; 00059 pc.printf( "\n\r" ); 00060 timer_t = t.read_ms( ); 00061 } 00062 loopCount ++; 00063 00064 // If any key was pressed 00065 if( key ) 00066 { 00067 // Display the key pressed on serial port 00068 pc.printf( "%c" , key ); 00069 } 00070 } 00071 }
Generated on Fri Jul 22 2022 04:37:14 by
1.7.2