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.
main.cpp@3:4bbef030b4b4, 2018-11-29 (annotated)
- Committer:
- mexx
- Date:
- Thu Nov 29 17:33:20 2018 +0000
- Revision:
- 3:4bbef030b4b4
- Parent:
- 2:73177929c8b4
- Child:
- 4:d3a068487721
3
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mexx | 0:ee837830d039 | 1 | #include "mbed.h" |
| mexx | 0:ee837830d039 | 2 | |
| mexx | 1:fb317288084d | 3 | BusOut allLeds(LED1, LED2, LED3, LED4); |
| mexx | 1:fb317288084d | 4 | BusOut zweiLeds(LED1, LED2); |
| mexx | 1:fb317288084d | 5 | |
| mexx | 0:ee837830d039 | 6 | //DigitalOut led1(LED1); |
| mexx | 0:ee837830d039 | 7 | //DigitalOut led2(LED2); |
| mexx | 0:ee837830d039 | 8 | //DigitalOut led3(LED3); |
| mexx | 0:ee837830d039 | 9 | //DigitalOut led4(LED4); |
| mexx | 1:fb317288084d | 10 | DigitalIn btn(P14); |
| mexx | 0:ee837830d039 | 11 | |
| mexx | 2:73177929c8b4 | 12 | enum Status {ST_LEDOFF=0, ST_LEDEIN=1,ST_Error}; |
| mexx | 3:4bbef030b4b4 | 13 | Stm volatile stm; |
| mexx | 2:73177929c8b4 | 14 | |
| mexx | 2:73177929c8b4 | 15 | class IsA : BusOut{ |
| mexx | 2:73177929c8b4 | 16 | |
| mexx | 2:73177929c8b4 | 17 | IsA():BusOut(LED1, LED2, LED3, LED4){}; |
| mexx | 2:73177929c8b4 | 18 | |
| mexx | 2:73177929c8b4 | 19 | void LedOFF(){write(0x00);} |
| mexx | 2:73177929c8b4 | 20 | |
| mexx | 2:73177929c8b4 | 21 | void LedON(int lVal){write(lVal)}; |
| mexx | 2:73177929c8b4 | 22 | void LedON(){write(0x0f);} |
| mexx | 2:73177929c8b4 | 23 | |
| mexx | 2:73177929c8b4 | 24 | }; |
| mexx | 2:73177929c8b4 | 25 | |
| mexx | 2:73177929c8b4 | 26 | class IsAnEvent : public InterruptIn { |
| mexx | 2:73177929c8b4 | 27 | volatile int16_t _pressed; |
| mexx | 2:73177929c8b4 | 28 | void _RisingISR(); |
| mexx | 0:ee837830d039 | 29 | public: |
| mexx | 2:73177929c8b4 | 30 | IsAnEvent() : InterruptIn(p15) {}; |
| mexx | 2:73177929c8b4 | 31 | IsAnEvent(PinName pin) : InterruptIn(pin) { |
| mexx | 2:73177929c8b4 | 32 | rise(callback(this, &IsAnEvent::_RisingISR)); |
| mexx | 2:73177929c8b4 | 33 | _pressed=0; |
| mexx | 2:73177929c8b4 | 34 | }; |
| mexx | 2:73177929c8b4 | 35 | int CheckFlag(); |
| mexx | 0:ee837830d039 | 36 | void InitIsr(); |
| mexx | 0:ee837830d039 | 37 | }; |
| mexx | 2:73177929c8b4 | 38 | |
| mexx | 2:73177929c8b4 | 39 | void IsAnEvent::InitIsr() { |
| mexx | 2:73177929c8b4 | 40 | rise(callback(this, &IsAnEvent::_RisingISR)); |
| mexx | 2:73177929c8b4 | 41 | } |
| mexx | 2:73177929c8b4 | 42 | |
| mexx | 2:73177929c8b4 | 43 | void IsAnEvent::_RisingISR() { |
| mexx | 3:4bbef030b4b4 | 44 | wait_ms(100); |
| mexx | 2:73177929c8b4 | 45 | if( read() ) |
| mexx | 2:73177929c8b4 | 46 | _pressed = true; |
| mexx | 3:4bbef030b4b4 | 47 | |
| mexx | 2:73177929c8b4 | 48 | } |
| mexx | 3:4bbef030b4b4 | 49 | |
| mexx | 3:4bbef030b4b4 | 50 | |
| mexx | 3:4bbef030b4b4 | 51 | IsAnEvent sw1(p14); // Joy Stick Center |
| mexx | 3:4bbef030b4b4 | 52 | |
| mexx | 2:73177929c8b4 | 53 | int IsAnEvent::CheckFlag() { |
| mexx | 0:ee837830d039 | 54 | if( _pressed ) { |
| mexx | 0:ee837830d039 | 55 | _pressed = false; |
| mexx | 0:ee837830d039 | 56 | return 1; |
| mexx | 0:ee837830d039 | 57 | } |
| mexx | 0:ee837830d039 | 58 | return 0; |
| mexx | 0:ee837830d039 | 59 | } |
| mexx | 2:73177929c8b4 | 60 | |
| mexx | 0:ee837830d039 | 61 | |
| mexx | 0:ee837830d039 | 62 | void stateMachine() |
| mexx | 0:ee837830d039 | 63 | { |
| mexx | 0:ee837830d039 | 64 | printf("state: %d\n", stm.state); |
| mexx | 0:ee837830d039 | 65 | switch (stm.state) |
| mexx | 0:ee837830d039 | 66 | { |
| mexx | 1:fb317288084d | 67 | case ST_LEDEIN: stm.Ein(); |
| mexx | 0:ee837830d039 | 68 | break; |
| mexx | 1:fb317288084d | 69 | case ST_LEDOFF: stm.Aus(); |
| mexx | 0:ee837830d039 | 70 | break; |
| mexx | 0:ee837830d039 | 71 | default: stm.Error(); |
| mexx | 0:ee837830d039 | 72 | break; |
| mexx | 0:ee837830d039 | 73 | } |
| mexx | 0:ee837830d039 | 74 | } |
| mexx | 3:4bbef030b4b4 | 75 | IsAnEvent sw1(p14); // Joy Stick Center |
| mexx | 3:4bbef030b4b4 | 76 | |
| mexx | 0:ee837830d039 | 77 | |
| mexx | 0:ee837830d039 | 78 | int main() |
| mexx | 0:ee837830d039 | 79 | { |
| mexx | 0:ee837830d039 | 80 | printf("Hello STM class\n"); |
| mexx | 0:ee837830d039 | 81 | sw1.InitIsr(); |
| mexx | 0:ee837830d039 | 82 | |
| mexx | 0:ee837830d039 | 83 | while(1) { |
| mexx | 0:ee837830d039 | 84 | stateMachine(); |
| mexx | 0:ee837830d039 | 85 | } |
| mexx | 0:ee837830d039 | 86 | } |
| mexx | 2:73177929c8b4 | 87 |