Demonstrates the simplest use of the matrix Keypad library.

Dependencies:   Hotboards_keypad mbed

Fork of HelloKeypad by Roman Valencia

Committer:
Hotboards
Date:
Tue Mar 08 21:16:19 2016 +0000
Revision:
1:29d7ab601f8f
Parent:
0:387ee84bc5dc
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Hotboards 1:29d7ab601f8f 1 /* @file HelloKeypad.cpp
Hotboards 1:29d7ab601f8f 2 || @version 1.1
Hotboards 1:29d7ab601f8f 3 || @modified by Diego (http://hotboards.org)
Hotboards 1:29d7ab601f8f 4 || @author Alexander Brevig
Hotboards 1:29d7ab601f8f 5 || @contact alexanderbrevig@gmail.com
Hotboards 1:29d7ab601f8f 6 ||
Hotboards 1:29d7ab601f8f 7 || @description
Hotboards 1:29d7ab601f8f 8 || | Demonstrates the simplest use of the matrix Keypad library.
Hotboards 1:29d7ab601f8f 9 || | Just press any key an it will be displayed on the serial port
Hotboards 1:29d7ab601f8f 10 || #
Hotboards 1:29d7ab601f8f 11 */
RomanValenciaP 0:387ee84bc5dc 12 #include "mbed.h"
RomanValenciaP 0:387ee84bc5dc 13 #include "Hotboards_keypad.h"
RomanValenciaP 0:387ee84bc5dc 14
RomanValenciaP 0:387ee84bc5dc 15 // Defines the keys array with it's respective number of rows & cols,
RomanValenciaP 0:387ee84bc5dc 16 // and with the value of each key
RomanValenciaP 0:387ee84bc5dc 17 char keys[ 4 ][ 4 ] =
RomanValenciaP 0:387ee84bc5dc 18 {
RomanValenciaP 0:387ee84bc5dc 19 { '1' , '2' , '3' , 'A' },
RomanValenciaP 0:387ee84bc5dc 20 { '4' , '5' , '6' , 'B' },
RomanValenciaP 0:387ee84bc5dc 21 { '7' , '8' , '9' , 'C' },
RomanValenciaP 0:387ee84bc5dc 22 { '*' , '0' , '#' , 'D' }
RomanValenciaP 0:387ee84bc5dc 23 };
RomanValenciaP 0:387ee84bc5dc 24
RomanValenciaP 0:387ee84bc5dc 25 // Defines the pins connected to the rows
RomanValenciaP 0:387ee84bc5dc 26 DigitalInOut rowPins[ 4 ] = { PA_6 , PA_7 , PB_6 , PC_7 };
RomanValenciaP 0:387ee84bc5dc 27 // Defines the pins connected to the cols
RomanValenciaP 0:387ee84bc5dc 28 DigitalInOut colPins[ 4 ] = { PA_8 , PB_10 , PB_4 , PB_5 };
RomanValenciaP 0:387ee84bc5dc 29
RomanValenciaP 0:387ee84bc5dc 30 // Creates a new keyboard with the values entered before
RomanValenciaP 0:387ee84bc5dc 31 Keypad kpd( makeKeymap( keys ) , rowPins , colPins , 4 , 4 );
RomanValenciaP 0:387ee84bc5dc 32
RomanValenciaP 0:387ee84bc5dc 33 // Configures the serial port
RomanValenciaP 0:387ee84bc5dc 34 Serial pc( USBTX , USBRX );
RomanValenciaP 0:387ee84bc5dc 35
RomanValenciaP 0:387ee84bc5dc 36 int main()
RomanValenciaP 0:387ee84bc5dc 37 {
RomanValenciaP 0:387ee84bc5dc 38 pc.printf( "Press any key: " );
RomanValenciaP 0:387ee84bc5dc 39 while(1)
RomanValenciaP 0:387ee84bc5dc 40 {
RomanValenciaP 0:387ee84bc5dc 41 // Poll the keypad to look for any activation
RomanValenciaP 0:387ee84bc5dc 42 char key = kpd.getKey( );
RomanValenciaP 0:387ee84bc5dc 43
RomanValenciaP 0:387ee84bc5dc 44 // If any key was pressed
RomanValenciaP 0:387ee84bc5dc 45 if( key )
RomanValenciaP 0:387ee84bc5dc 46 {
RomanValenciaP 0:387ee84bc5dc 47 // Display the key pressed on serial port
RomanValenciaP 0:387ee84bc5dc 48 pc.printf( "%c" , key );
RomanValenciaP 0:387ee84bc5dc 49 pc.printf( "\n\r" );
RomanValenciaP 0:387ee84bc5dc 50 }
RomanValenciaP 0:387ee84bc5dc 51 }
RomanValenciaP 0:387ee84bc5dc 52 }