Keypad
Dependencies: Hotboards_keypad mbed
Revision 2:61dd34b05a49, committed 2018-08-21
- Comitter:
- shivanandgowdakr
- Date:
- Tue Aug 21 10:56:52 2018 +0000
- Parent:
- 1:e6112104a80f
- Commit message:
- Qwerty Keypad
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hotboards_keypad.lib Tue Aug 21 10:56:52 2018 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/Hotboards/code/Hotboards_keypad/#e870110f753b
--- a/main.cpp Wed Jun 07 14:08:05 2017 +0000
+++ b/main.cpp Tue Aug 21 10:56:52 2018 +0000
@@ -1,14 +1,55 @@
+/* @file HelloKeypad.cpp
+|| @version 1.1
+|| @modified by Diego (http://hotboards.org)
+|| @author Alexander Brevig
+|| @contact alexanderbrevig@gmail.com
+||
+|| @description
+|| | Demonstrates the simplest use of the matrix Keypad library.
+|| | Just press any key an it will be displayed on the serial port
+|| #
+*/
#include "mbed.h"
-
-SPI device(SPI_MOSI, SPI_MISO, SPI_SCK);
-
-int main() {
- int i = 0;
- while(1) {
- device.write(0x55);
- device.write(i++);
- device.write(0xE0);
- wait_us(50);
+#include "Hotboards_keypad.h"
+
+// Defines the keys array with it's respective number of rows & cols,
+// and with the value of each key
+char keys[ 7 ][ 7 ] =
+{
+ { '1' , '2' , '3' , '4', '5', '6' ,'a'},
+ { '7' , '8' , '9' , '0', 'Q', 'W' ,'b'},
+ { 'E' , 'R' , 'T' , 'Y', 'U', 'I' ,'c'},
+ { 'O' , 'P' , 'A' , 'S', 'D', 'F' ,'d'},
+ { 'G' , 'H' , 'J' , 'K', 'L', 'Z' ,'e'},
+ { 'X' , 'C' , 'V' , 'B', 'N', 'M' ,'f'},
+ { 0x0D , 0x20 , 0x08 , 'g','h','i','j'}, //0x0D -> Enter Key , 0x20 -> Space, 0x08-> Backspace, a , b, c may be used as functions keys.
+};
+
+// Defines the pins connected to the rows
+DigitalInOut rowPins[ 7 ] = { D0,D1,D2,D3,D4,D5,D6};
+// Defines the pins connected to the cols
+DigitalInOut colPins[ 7 ] = { D7,D8,D9,D10,D11,D12,D13};
+
+// Creates a new keyboard with the values entered before
+Keypad kpd( makeKeymap( keys ) , rowPins , colPins , 7 , 7 );
+
+// Configures the serial port
+Serial pc( USBTX , USBRX );
+
+int main()
+{
+ pc.printf( "Press any key: " );
+ while(1)
+ {
+ // Poll the keypad to look for any activation
+ char key = kpd.waitForKey();
+
+ // If any key was pressed
+ if( key )
+ {
+ // Display the key pressed on serial port
+ pc.printf( "Pressed key is : %c" , key );
+ pc.printf( "\n\r" );
+ }
}
}
-
\ No newline at end of file
--- a/mbed.bld Wed Jun 07 14:08:05 2017 +0000 +++ b/mbed.bld Tue Aug 21 10:56:52 2018 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/mbed_official/code/mbed/builds/86740a56073b \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/5aab5a7997ee \ No newline at end of file