Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos X_NUCLEO_IHM02A1
main.cpp@33:de144094bdd1, 2019-04-22 (annotated)
- Committer:
- hagenrap
- Date:
- Mon Apr 22 11:56:38 2019 +0000
- Revision:
- 33:de144094bdd1
- Parent:
- 30:e464b2bb2376
- Child:
- 34:0dee9a606869
update raphi;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hagenrap | 33:de144094bdd1 | 1 | #include "SETUP.h" |
Davidroid | 1:9f1974b0960d | 2 | |
Davidroid | 0:5148e9486cf2 | 3 | |
scherfa2 | 27:23bd03a6a6f6 | 4 | /* Status Spleisser definieren*/ |
scherfa2 | 27:23bd03a6a6f6 | 5 | int StatusSpleisser = ST_SOLO; |
scherfa2 | 27:23bd03a6a6f6 | 6 | |
scherfa2 | 27:23bd03a6a6f6 | 7 | /*Input initalisieren für Status Spleisser*/ |
hagenrap | 33:de144094bdd1 | 8 | DigitalIn InputKontrollmodul(COM_SIGNAL); |
hagenrap | 33:de144094bdd1 | 9 | |
hagenrap | 33:de144094bdd1 | 10 | |
hagenrap | 33:de144094bdd1 | 11 | |
scherfa2 | 27:23bd03a6a6f6 | 12 | |
hagenrap | 33:de144094bdd1 | 13 | |
hagenrap | 33:de144094bdd1 | 14 | |
hagenrap | 33:de144094bdd1 | 15 | //------------------------------------------------------------------------------ |
hagenrap | 33:de144094bdd1 | 16 | //------------------------------------------------------------------------------ |
scherfa2 | 27:23bd03a6a6f6 | 17 | InterruptIn button1(USER_BUTTON); |
scherfa2 | 27:23bd03a6a6f6 | 18 | volatile int idx = 0; |
scherfa2 | 27:23bd03a6a6f6 | 19 | volatile bool button1_pressed = false; // Used in the main loop |
scherfa2 | 27:23bd03a6a6f6 | 20 | volatile bool button1_enabled = true; // Used for debouncing |
scherfa2 | 27:23bd03a6a6f6 | 21 | Timeout button1_timeout; // Used for debouncing |
scherfa2 | 27:23bd03a6a6f6 | 22 | |
scherfa2 | 27:23bd03a6a6f6 | 23 | // Enables button when bouncing is over |
scherfa2 | 27:23bd03a6a6f6 | 24 | void button1_enabled_cb(void) |
scherfa2 | 27:23bd03a6a6f6 | 25 | { |
scherfa2 | 27:23bd03a6a6f6 | 26 | button1_enabled = true; |
scherfa2 | 27:23bd03a6a6f6 | 27 | } |
scherfa2 | 27:23bd03a6a6f6 | 28 | |
scherfa2 | 27:23bd03a6a6f6 | 29 | // ISR handling button pressed event |
scherfa2 | 27:23bd03a6a6f6 | 30 | void button1_onpressed_cb(void) |
scherfa2 | 27:23bd03a6a6f6 | 31 | { |
scherfa2 | 27:23bd03a6a6f6 | 32 | if (button1_enabled) { // Disabled while the button is bouncing |
scherfa2 | 27:23bd03a6a6f6 | 33 | button1_enabled = false; |
scherfa2 | 27:23bd03a6a6f6 | 34 | button1_pressed = true; // To be read by the main loop |
scherfa2 | 27:23bd03a6a6f6 | 35 | |
scherfa2 | 27:23bd03a6a6f6 | 36 | if(idx<4){ |
scherfa2 | 27:23bd03a6a6f6 | 37 | idx++; |
scherfa2 | 27:23bd03a6a6f6 | 38 | } |
scherfa2 | 27:23bd03a6a6f6 | 39 | else{idx=1;} |
scherfa2 | 27:23bd03a6a6f6 | 40 | |
scherfa2 | 27:23bd03a6a6f6 | 41 | button1_timeout.attach(callback(button1_enabled_cb), 0.03); // Debounce time 300 ms |
scherfa2 | 27:23bd03a6a6f6 | 42 | } |
scherfa2 | 27:23bd03a6a6f6 | 43 | } |
hagenrap | 33:de144094bdd1 | 44 | //------------------------------------------------------------------------------ |
hagenrap | 33:de144094bdd1 | 45 | //------------------------------------------------------------------------------ |
hagenrap | 33:de144094bdd1 | 46 | |
hagenrap | 33:de144094bdd1 | 47 | |
hagenrap | 33:de144094bdd1 | 48 | |
Davidroid | 0:5148e9486cf2 | 49 | |
Davidroid | 0:5148e9486cf2 | 50 | |
Davidroid | 9:f35fbeedb8f4 | 51 | |
Davidroid | 0:5148e9486cf2 | 52 | /* Main ----------------------------------------------------------------------*/ |
Davidroid | 0:5148e9486cf2 | 53 | |
Davidroid | 0:5148e9486cf2 | 54 | int main() |
Davidroid | 0:5148e9486cf2 | 55 | { |
Davidroid | 1:9f1974b0960d | 56 | /*----- Initialization. -----*/ |
scherfa2 | 27:23bd03a6a6f6 | 57 | |
scherfa2 | 30:e464b2bb2376 | 58 | SchrittmotorenInit(); |
scherfa2 | 27:23bd03a6a6f6 | 59 | button1.fall(callback(button1_onpressed_cb)); // Attach ISR to handle button press event |
Davidroid | 18:591a007effc2 | 60 | |
scherfa2 | 27:23bd03a6a6f6 | 61 | while(1) |
scherfa2 | 27:23bd03a6a6f6 | 62 | { |
scherfa2 | 27:23bd03a6a6f6 | 63 | switch (StatusSpleisser) |
scherfa2 | 27:23bd03a6a6f6 | 64 | { |
scherfa2 | 27:23bd03a6a6f6 | 65 | case ST_SOLO: |
hagenrap | 33:de144094bdd1 | 66 | if(InputKontrollmodul == 0) |
scherfa2 | 27:23bd03a6a6f6 | 67 | { |
scherfa2 | 27:23bd03a6a6f6 | 68 | EntrySOLO(); |
scherfa2 | 27:23bd03a6a6f6 | 69 | } |
scherfa2 | 27:23bd03a6a6f6 | 70 | else |
scherfa2 | 27:23bd03a6a6f6 | 71 | { |
scherfa2 | 27:23bd03a6a6f6 | 72 | StatusSpleisser = ST_DUO; |
scherfa2 | 27:23bd03a6a6f6 | 73 | } |
scherfa2 | 27:23bd03a6a6f6 | 74 | break; |
scherfa2 | 27:23bd03a6a6f6 | 75 | case ST_DUO: |
hagenrap | 33:de144094bdd1 | 76 | if(InputKontrollmodul == 1) |
scherfa2 | 27:23bd03a6a6f6 | 77 | { |
scherfa2 | 27:23bd03a6a6f6 | 78 | EntryDUO(); |
scherfa2 | 27:23bd03a6a6f6 | 79 | } |
scherfa2 | 27:23bd03a6a6f6 | 80 | else |
scherfa2 | 27:23bd03a6a6f6 | 81 | { |
scherfa2 | 27:23bd03a6a6f6 | 82 | StatusSpleisser = ST_SOLO; |
scherfa2 | 27:23bd03a6a6f6 | 83 | } |
scherfa2 | 27:23bd03a6a6f6 | 84 | break; |
scherfa2 | 27:23bd03a6a6f6 | 85 | |
scherfa2 | 27:23bd03a6a6f6 | 86 | } |
Davidroid | 22:e81ccf73bc5d | 87 | } |
Davidroid | 22:e81ccf73bc5d | 88 | } |