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