/*############################################################# Program Name : ex1_Keypad_simple Author : Grant Phillips Date Modified : 05/04/2016 Compiler : ARMmbed Tested On : STM32F4-Discovery Description : Example program that demonstrates the use of the Keypad class to use when a 4x4 keypad using a polling method. As the user presses a key, that character will be display via the Serial Wire Viewer as demonstration. When the user presses the '*' key, a newline will be displayed. The output is displayed on a PC using the Serial Wire Viewer (SWV). See the SWV examples for an explanation of the use of this feature. Requirements : * STM32F4-Discovery Board Circuit : * 4x4 Keypad connected as follows: COL1 (pin1) - PE15 COL2 (pin2) - PE14 COL3 (pin3) - PE13 COL4 (pin4) - PE12 ROW1 (pin5) - PE11 ROW2 (pin6) - PE10 ROW3 (pin7) - PE9 ROW4 (pin8) - PE8 * A wire link between PB3 and pin6 of the SWD connector (CN2) as explained in the SWV examples section ##############################################################*/ #include "mbed.h" #include "Keypad.h" #include "SWO.h" Keypad kpad(PE_15, PE_14, PE_13, PE_12, PE_11, PE_10, PE_9, PE_8); //col1, col2, col3, col4, row1, row2, row3, row4 SWO_Channel SWO; int main() { char key; int released = 1; //flag for indicating if a key was released (=1) or not (=0) while(1) { key = kpad.ReadKey(); //read the current key pressed, but don't wait for a key to be pressed if(key == '\0') //if no key is pressed released = 1; //set the flag when all keys are released if((key != '\0') && (released == 1)) { //if a key is pressed AND previous key was released if(key == '*') SWO.printf("\n"); //print newline when '*' is pressed else SWO.printf("%c", key); //otherwise print the key pressed released = 0; //clear the flag to indicate that key is still pressed } } }