Shivanand Gowda / Mbed 2 deprecated Qwerty_Keypad

Dependencies:   Hotboards_keypad mbed

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[ 7 ][ 7 ] =
00018 {
00019     { '1' , '2' , '3' , '4', '5', '6' ,'a'},
00020     { '7' , '8' , '9' , '0', 'Q', 'W' ,'b'},
00021     { 'E' , 'R' , 'T' , 'Y', 'U', 'I' ,'c'},
00022     { 'O' , 'P' , 'A' , 'S', 'D', 'F' ,'d'},
00023     { 'G' , 'H' , 'J' , 'K', 'L', 'Z' ,'e'},
00024     { 'X' , 'C' , 'V' , 'B', 'N', 'M' ,'f'},
00025     { 0x0D , 0x20 , 0x08 , 'g','h','i','j'},     //0x0D -> Enter Key , 0x20 -> Space, 0x08-> Backspace, a , b, c may be used as functions keys.    
00026 };
00027 
00028 // Defines the pins connected to the rows
00029 DigitalInOut rowPins[ 7 ] = { D0,D1,D2,D3,D4,D5,D6};
00030 // Defines the pins connected to the cols
00031 DigitalInOut colPins[ 7 ] = { D7,D8,D9,D10,D11,D12,D13};
00032 
00033 // Creates a new keyboard with the values entered before
00034 Keypad kpd( makeKeymap( keys ) , rowPins , colPins , 7 , 7 );
00035 
00036 // Configures the serial port
00037 Serial pc( USBTX , USBRX );
00038 
00039 int main()
00040 {
00041     pc.printf( "Press any key: " );
00042     while(1)
00043     {
00044         // Poll the keypad to look for any activation
00045         char key = kpd.waitForKey();
00046         
00047         // If any key was pressed
00048         if( key )
00049         {
00050             // Display the key pressed on serial port
00051             pc.printf( "Pressed key is   : %c" , key );
00052             pc.printf( "\n\r" );
00053         }
00054     }
00055 }