/*############################################################# Program Name : ex8_button_count Author : Grant Phillips Date Modified : 12/01/2016 Compiler : ARMmbed Tested On : STM32F4-Discovery Description : Increments a counter from 0 to 255 when a button is pushed and released. The count value is displayed on 8 LEDs. Due to the contact bounce effect on the button, the counter will count fairly inconsistend. The example ex9_button_count_debounce will solve this. 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) count = count + 1; //increment count myleds = count; //display count on LEDs while(button == 0) { //wait for the pushbutton to be released //do nothing } } } }