Hotboards MX / Mbed 2 deprecated Hotboards_HelloKeypad

Dependencies:   Hotboards_keypad mbed

Fork of HelloKeypad by Roman Valencia

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* @file HelloKeypad.cpp
00002 || @version 1.1
00003 || @modified by Diego (http://hotboards.org)
00004 || @author Alexander Brevig
00005 || @contact alexanderbrevig@gmail.com
00006 ||
00007 || @description
00008 || | Demonstrates the simplest use of the matrix Keypad library.
00009 || | Just press any key an it will be displayed on the serial port
00010 || #
00011 */
00012 #include "mbed.h"
00013 #include "Hotboards_keypad.h"
00014 
00015 // Defines the keys array with it's respective number of rows & cols,
00016 // and with the value of each key
00017 char keys[ 4 ][ 4 ] =
00018 {
00019     { '1' , '2' , '3' , 'A' },
00020     { '4' , '5' , '6' , 'B' },
00021     { '7' , '8' , '9' , 'C' },
00022     { '*' , '0' , '#' , 'D' }
00023 };
00024 
00025 // Defines the pins connected to the rows
00026 DigitalInOut rowPins[ 4 ] = { PA_6 , PA_7 , PB_6 , PC_7 };
00027 // Defines the pins connected to the cols
00028 DigitalInOut colPins[ 4 ] = { PA_8 , PB_10 , PB_4 , PB_5 };
00029 
00030 // Creates a new keyboard with the values entered before
00031 Keypad kpd( makeKeymap( keys ) , rowPins , colPins , 4 , 4 );
00032 
00033 // Configures the serial port
00034 Serial pc( USBTX , USBRX );
00035 
00036 int main()
00037 {
00038     pc.printf( "Press any key: " );
00039     while(1)
00040     {
00041         // Poll the keypad to look for any activation
00042         char key = kpd.getKey( );
00043         
00044         // If any key was pressed
00045         if( key )
00046         {
00047             // Display the key pressed on serial port
00048             pc.printf( "%c" , key );
00049             pc.printf( "\n\r" );
00050         }
00051     }
00052 }