Oliver Ainhirn
/
Interrupt
main.cpp@0:1992191bb2b6, 2019-02-04 (annotated)
- Committer:
- corsa1600
- Date:
- Mon Feb 04 16:55:02 2019 +0000
- Revision:
- 0:1992191bb2b6
Interrupt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
corsa1600 | 0:1992191bb2b6 | 1 | #include "mbed.h" |
corsa1600 | 0:1992191bb2b6 | 2 | |
corsa1600 | 0:1992191bb2b6 | 3 | DigitalOut led (LED1); |
corsa1600 | 0:1992191bb2b6 | 4 | |
corsa1600 | 0:1992191bb2b6 | 5 | |
corsa1600 | 0:1992191bb2b6 | 6 | class SwEvent |
corsa1600 | 0:1992191bb2b6 | 7 | { |
corsa1600 | 0:1992191bb2b6 | 8 | private: |
corsa1600 | 0:1992191bb2b6 | 9 | InterruptIn _isr; |
corsa1600 | 0:1992191bb2b6 | 10 | bool _check; |
corsa1600 | 0:1992191bb2b6 | 11 | public: |
corsa1600 | 0:1992191bb2b6 | 12 | SwEvent(PinName isr):_isr(isr) |
corsa1600 | 0:1992191bb2b6 | 13 | { |
corsa1600 | 0:1992191bb2b6 | 14 | _isr.rise(callback(this, &SwEvent::setFlag)); |
corsa1600 | 0:1992191bb2b6 | 15 | } |
corsa1600 | 0:1992191bb2b6 | 16 | |
corsa1600 | 0:1992191bb2b6 | 17 | bool checkFlag(void); |
corsa1600 | 0:1992191bb2b6 | 18 | void setFlag(void); |
corsa1600 | 0:1992191bb2b6 | 19 | }; |
corsa1600 | 0:1992191bb2b6 | 20 | |
corsa1600 | 0:1992191bb2b6 | 21 | |
corsa1600 | 0:1992191bb2b6 | 22 | |
corsa1600 | 0:1992191bb2b6 | 23 | void SwEvent::setFlag(void) |
corsa1600 | 0:1992191bb2b6 | 24 | { |
corsa1600 | 0:1992191bb2b6 | 25 | _check = !_check; |
corsa1600 | 0:1992191bb2b6 | 26 | } |
corsa1600 | 0:1992191bb2b6 | 27 | |
corsa1600 | 0:1992191bb2b6 | 28 | bool SwEvent::checkFlag(void) |
corsa1600 | 0:1992191bb2b6 | 29 | { |
corsa1600 | 0:1992191bb2b6 | 30 | |
corsa1600 | 0:1992191bb2b6 | 31 | if (_check == 0) led = 1; |
corsa1600 | 0:1992191bb2b6 | 32 | else if (_check == 1) led = 0; |
corsa1600 | 0:1992191bb2b6 | 33 | |
corsa1600 | 0:1992191bb2b6 | 34 | return _check; |
corsa1600 | 0:1992191bb2b6 | 35 | } |
corsa1600 | 0:1992191bb2b6 | 36 | |
corsa1600 | 0:1992191bb2b6 | 37 | SwEvent checker(p15); |
corsa1600 | 0:1992191bb2b6 | 38 | |
corsa1600 | 0:1992191bb2b6 | 39 | int main() { |
corsa1600 | 0:1992191bb2b6 | 40 | while(1) { |
corsa1600 | 0:1992191bb2b6 | 41 | checker.checkFlag(); |
corsa1600 | 0:1992191bb2b6 | 42 | printf("Aktueller Status: %d \n", checker.checkFlag()); |
corsa1600 | 0:1992191bb2b6 | 43 | wait_ms(10); |
corsa1600 | 0:1992191bb2b6 | 44 | } |
corsa1600 | 0:1992191bb2b6 | 45 | } |