Update
Dependencies: mbed mbed-rtos X_NUCLEO_IHM02A1
Buttons.cpp
- Committer:
- scherfa2
- Date:
- 2019-05-13
- Revision:
- 38:3776ee18e56f
- Parent:
- 37:a74d377d8f74
- Child:
- 42:0aaa3b282b6e
File content as of revision 38:3776ee18e56f:
#include "SETUP.h" extern DigitalIn Button1; extern DigitalIn Button2; /* extern volatile bool buttonSTART_pressed; // Used in the main loop extern volatile bool buttonSTART_enabled; // Used for debouncing extern Timeout buttonSTART_timeout; // Used for debouncing extern volatile bool buttonAbbruch_pressed; // Used in the main loop extern volatile bool buttonAbbruch_enabled; // Used for debouncing extern Timeout buttonAbbruch_timeout; // Used for debouncing */ /* --------------------------- START_BUTTON --------------------------------- // Enables button when bouncing is over void buttonSTART_enabled_cb(void) { buttonSTART_enabled = true; } void buttonSTART_diable_cb(void) { buttonSTART_enabled = false; } // ISR handling button pressed event void buttonSTART_onpressed_cb(void) { if (buttonSTART_enabled) { // Disabled while the button is bouncing buttonSTART_enabled = false; buttonSTART_pressed = true; // To be read by the main loop buttonSTART_timeout.attach(callback(buttonSTART_enabled_cb), 0.300); // Debounce time 300 ms } } /* ---------------------------------- END ----------------------------------- */ /* ------------------------- ABBRUCH_BUTTON --------------------------------- // Enables button when bouncing is over void buttonAbbruch_enabled_cb(void) { buttonAbbruch_enabled = true; } void buttonAbbruch_diable_cb(void) { buttonAbbruch_enabled = false; } // ISR handling button pressed event void buttonAbbruch_onpressed_cb(void) { if (buttonAbbruch_enabled) { // Disabled while the button is bouncing buttonAbbruch_enabled = false; buttonAbbruch_pressed = true; // To be read by the main loop buttonAbbruch_timeout.attach(callback(buttonAbbruch_enabled_cb), 0.300); // Debounce time 300 ms } } */ bool get_Button_1() { if(Button1 == 1) { wait(0.01); if(Button1 == 1) { return true; } } else if(Button1 == 0) { wait(0.01); if(Button1 == 0) { return false; } } else return false; } bool get_Button_2() { if(Button2 == 1) { wait(0.01); if(Button2 == 1) { return true; } } else if(Button2 == 0) { wait(0.01); if(Button2 == 0) { return false; } } else return false; } /* ---------------------------------- END ----------------------------------- */