/*############################################################# Program Name : ex9_button_count_debounce Author : Grant Phillips Date Modified : 12/01/2016 Compiler : ARMmbed Tested On : STM32F4-Discovery Description : This is the upgrade of ex8_button_count to compensate for the debounce effect on the pushbutton which causes the inconsistend counting. Requirements : * STM32F4-Discovery Board Circuit : * 8 LEDs connected to PD15 - PD8 * a pushbutton connected to PE8 with a pullup resitor ##############################################################*/ #include "mbed.h" BusOut myleds(PD_8, PD_9, PD_10, PD_11, PD_12, PD_13, PD_14, PD_15); // bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 . . . DigitalIn button(PE_8); int main() { uint8_t count=0; while(1) { if(button == 0) { //is the pushbutton pressed (input = 0) wait(0.01); //wait 10ms for debounce if(button == 0) { //is the pushbutton still pressed? count = count + 1; //increment count myleds = count; //display count on LEDs while(button == 0) { //wait for the pushbutton to be released //do nothing } } } } }