mit Buttons/PWM als einzelne cpp und init in main
Dependencies: mbed mbed-rtos X_NUCLEO_IHM02A1
main.cpp
- Committer:
- hagenrap
- Date:
- 2019-04-22
- Revision:
- 33:de144094bdd1
- Parent:
- 30:e464b2bb2376
- Child:
- 34:0dee9a606869
File content as of revision 33:de144094bdd1:
#include "SETUP.h" /* Status Spleisser definieren*/ int StatusSpleisser = ST_SOLO; /*Input initalisieren für Status Spleisser*/ DigitalIn InputKontrollmodul(COM_SIGNAL); //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ InterruptIn button1(USER_BUTTON); volatile int idx = 0; volatile bool button1_pressed = false; // Used in the main loop volatile bool button1_enabled = true; // Used for debouncing Timeout button1_timeout; // Used for debouncing // Enables button when bouncing is over void button1_enabled_cb(void) { button1_enabled = true; } // ISR handling button pressed event void button1_onpressed_cb(void) { if (button1_enabled) { // Disabled while the button is bouncing button1_enabled = false; button1_pressed = true; // To be read by the main loop if(idx<4){ idx++; } else{idx=1;} button1_timeout.attach(callback(button1_enabled_cb), 0.03); // Debounce time 300 ms } } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ /* Main ----------------------------------------------------------------------*/ int main() { /*----- Initialization. -----*/ SchrittmotorenInit(); button1.fall(callback(button1_onpressed_cb)); // Attach ISR to handle button press event while(1) { switch (StatusSpleisser) { case ST_SOLO: if(InputKontrollmodul == 0) { EntrySOLO(); } else { StatusSpleisser = ST_DUO; } break; case ST_DUO: if(InputKontrollmodul == 1) { EntryDUO(); } else { StatusSpleisser = ST_SOLO; } break; } } }