![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
pachas
Dependencies: mbed QEI FastPWM
Diff: buttons.cpp
- Revision:
- 0:9d0b9785d3d6
- Child:
- 1:aa5df1878126
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/buttons.cpp Sat Apr 11 22:53:05 2020 +0000 @@ -0,0 +1,33 @@ + +#include "mbed.h" +#include "buttons.h" + + +/* Object definition */ +BusIn buttons (ENTER_SW_PIN, LIMIT_SW_01_PIN, GAS_INPUT_SW_PIN); + +/* Global variable definition */ +volatile uint8_t button_state = 0; // debounced button state (bit == 1: button pressed) +volatile uint8_t button_press = 0; // button press detect + + + +void Buttons_Initialize(void){ + // Enable the pull-up resistors for the buttons and the switch + buttons.mode(PullUp); +} + + + +/**************************************************************** + getButtonPress: check if a button has been pressed. + Each pressed key is reported only once +*****************************************************************/ + +uint8_t Get_Button_Press(uint8_t button_mask){ + __disable_irq(); // disable interrupts + button_mask &= button_press; // read button(s) + button_press ^= button_mask; // clear button(s) + __enable_irq(); // enable interrupts + return button_mask; +} \ No newline at end of file