![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
RGB Dimmer mit Klassen
Dependencies: mbed
BtnEventM0.h@0:2af9d1c6c6ee, 2014-12-12 (annotated)
- Committer:
- Kilian
- Date:
- Fri Dec 12 17:21:54 2014 +0000
- Revision:
- 0:2af9d1c6c6ee
RGB Dimmerprogramm mit Klassen
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kilian | 0:2af9d1c6c6ee | 1 | |
Kilian | 0:2af9d1c6c6ee | 2 | |
Kilian | 0:2af9d1c6c6ee | 3 | class BtnEventM0 |
Kilian | 0:2af9d1c6c6ee | 4 | { |
Kilian | 0:2af9d1c6c6ee | 5 | public: |
Kilian | 0:2af9d1c6c6ee | 6 | int16_t pressed; |
Kilian | 0:2af9d1c6c6ee | 7 | |
Kilian | 0:2af9d1c6c6ee | 8 | BtnEventM0(PinName pin) : _isr(pin) { |
Kilian | 0:2af9d1c6c6ee | 9 | pressed=0; |
Kilian | 0:2af9d1c6c6ee | 10 | } |
Kilian | 0:2af9d1c6c6ee | 11 | |
Kilian | 0:2af9d1c6c6ee | 12 | int CheckFlag() { |
Kilian | 0:2af9d1c6c6ee | 13 | if( pressed ) { |
Kilian | 0:2af9d1c6c6ee | 14 | pressed=0; |
Kilian | 0:2af9d1c6c6ee | 15 | return 1; |
Kilian | 0:2af9d1c6c6ee | 16 | } |
Kilian | 0:2af9d1c6c6ee | 17 | return 0; |
Kilian | 0:2af9d1c6c6ee | 18 | } |
Kilian | 0:2af9d1c6c6ee | 19 | |
Kilian | 0:2af9d1c6c6ee | 20 | void CheckButton() { |
Kilian | 0:2af9d1c6c6ee | 21 | if( _isr.read() ) |
Kilian | 0:2af9d1c6c6ee | 22 | pressed = 1; |
Kilian | 0:2af9d1c6c6ee | 23 | } |
Kilian | 0:2af9d1c6c6ee | 24 | |
Kilian | 0:2af9d1c6c6ee | 25 | void Init() { |
Kilian | 0:2af9d1c6c6ee | 26 | _isr.rise(this, &BtnEventM0::RisingISR); |
Kilian | 0:2af9d1c6c6ee | 27 | } |
Kilian | 0:2af9d1c6c6ee | 28 | |
Kilian | 0:2af9d1c6c6ee | 29 | void RisingISR() { |
Kilian | 0:2af9d1c6c6ee | 30 | if( _isr.read() ) |
Kilian | 0:2af9d1c6c6ee | 31 | pressed = 1; |
Kilian | 0:2af9d1c6c6ee | 32 | } |
Kilian | 0:2af9d1c6c6ee | 33 | protected: |
Kilian | 0:2af9d1c6c6ee | 34 | InterruptIn _isr; |
Kilian | 0:2af9d1c6c6ee | 35 | }; |
Kilian | 0:2af9d1c6c6ee | 36 | |
Kilian | 0:2af9d1c6c6ee | 37 | /* |
Kilian | 0:2af9d1c6c6ee | 38 | class BtnEventM02 : public BtnEventM0 |
Kilian | 0:2af9d1c6c6ee | 39 | { |
Kilian | 0:2af9d1c6c6ee | 40 | public: |
Kilian | 0:2af9d1c6c6ee | 41 | BtnEventM02(PinName pin) : BtnEventM0(pin) { |
Kilian | 0:2af9d1c6c6ee | 42 | _tm.stop(); |
Kilian | 0:2af9d1c6c6ee | 43 | _tm.reset(); |
Kilian | 0:2af9d1c6c6ee | 44 | _state=1; |
Kilian | 0:2af9d1c6c6ee | 45 | } |
Kilian | 0:2af9d1c6c6ee | 46 | |
Kilian | 0:2af9d1c6c6ee | 47 | void Init() { |
Kilian | 0:2af9d1c6c6ee | 48 | _isr.rise(this, &BtnEventM02::RisingISR); |
Kilian | 0:2af9d1c6c6ee | 49 | } |
Kilian | 0:2af9d1c6c6ee | 50 | |
Kilian | 0:2af9d1c6c6ee | 51 | void RisingISR() { |
Kilian | 0:2af9d1c6c6ee | 52 | if( !_isr.read() ) |
Kilian | 0:2af9d1c6c6ee | 53 | return; |
Kilian | 0:2af9d1c6c6ee | 54 | pressed = 1; |
Kilian | 0:2af9d1c6c6ee | 55 | _tm.start(); |
Kilian | 0:2af9d1c6c6ee | 56 | _state = 2; |
Kilian | 0:2af9d1c6c6ee | 57 | } |
Kilian | 0:2af9d1c6c6ee | 58 | |
Kilian | 0:2af9d1c6c6ee | 59 | void CheckButton() { |
Kilian | 0:2af9d1c6c6ee | 60 | if( _state==1 ) |
Kilian | 0:2af9d1c6c6ee | 61 | return; |
Kilian | 0:2af9d1c6c6ee | 62 | if( _state==2 ) { |
Kilian | 0:2af9d1c6c6ee | 63 | if( !_isr.read() ) { |
Kilian | 0:2af9d1c6c6ee | 64 | _state = 1; |
Kilian | 0:2af9d1c6c6ee | 65 | return; |
Kilian | 0:2af9d1c6c6ee | 66 | } |
Kilian | 0:2af9d1c6c6ee | 67 | if( _tm.read_ms()>500 ) { |
Kilian | 0:2af9d1c6c6ee | 68 | _tm.reset(); |
Kilian | 0:2af9d1c6c6ee | 69 | _state = 3; |
Kilian | 0:2af9d1c6c6ee | 70 | pressed = 1; |
Kilian | 0:2af9d1c6c6ee | 71 | } |
Kilian | 0:2af9d1c6c6ee | 72 | } else if( _state==3 ) { |
Kilian | 0:2af9d1c6c6ee | 73 | if( !_isr.read() ) { |
Kilian | 0:2af9d1c6c6ee | 74 | _state = 1; |
Kilian | 0:2af9d1c6c6ee | 75 | return; |
Kilian | 0:2af9d1c6c6ee | 76 | } |
Kilian | 0:2af9d1c6c6ee | 77 | if( _tm.read_ms()>100 ) { |
Kilian | 0:2af9d1c6c6ee | 78 | _tm.reset(); |
Kilian | 0:2af9d1c6c6ee | 79 | _state = 3; |
Kilian | 0:2af9d1c6c6ee | 80 | pressed = 1; |
Kilian | 0:2af9d1c6c6ee | 81 | } |
Kilian | 0:2af9d1c6c6ee | 82 | } |
Kilian | 0:2af9d1c6c6ee | 83 | } |
Kilian | 0:2af9d1c6c6ee | 84 | private: |
Kilian | 0:2af9d1c6c6ee | 85 | int16_t _state; |
Kilian | 0:2af9d1c6c6ee | 86 | Timer _tm; |
Kilian | 0:2af9d1c6c6ee | 87 | }; |
Kilian | 0:2af9d1c6c6ee | 88 | */ |
Kilian | 0:2af9d1c6c6ee | 89 | |
Kilian | 0:2af9d1c6c6ee | 90 | |
Kilian | 0:2af9d1c6c6ee | 91 | |
Kilian | 0:2af9d1c6c6ee | 92 | |
Kilian | 0:2af9d1c6c6ee | 93 | |
Kilian | 0:2af9d1c6c6ee | 94 | |
Kilian | 0:2af9d1c6c6ee | 95 | |
Kilian | 0:2af9d1c6c6ee | 96 | |
Kilian | 0:2af9d1c6c6ee | 97 | |
Kilian | 0:2af9d1c6c6ee | 98 | |
Kilian | 0:2af9d1c6c6ee | 99 | |
Kilian | 0:2af9d1c6c6ee | 100 | |
Kilian | 0:2af9d1c6c6ee | 101 | |
Kilian | 0:2af9d1c6c6ee | 102 | |
Kilian | 0:2af9d1c6c6ee | 103 | |
Kilian | 0:2af9d1c6c6ee | 104 | |
Kilian | 0:2af9d1c6c6ee | 105 | |
Kilian | 0:2af9d1c6c6ee | 106 | |
Kilian | 0:2af9d1c6c6ee | 107 | |
Kilian | 0:2af9d1c6c6ee | 108 | |
Kilian | 0:2af9d1c6c6ee | 109 | |
Kilian | 0:2af9d1c6c6ee | 110 | |
Kilian | 0:2af9d1c6c6ee | 111 | |
Kilian | 0:2af9d1c6c6ee | 112 | |
Kilian | 0:2af9d1c6c6ee | 113 | |
Kilian | 0:2af9d1c6c6ee | 114 | |
Kilian | 0:2af9d1c6c6ee | 115 | |
Kilian | 0:2af9d1c6c6ee | 116 | |
Kilian | 0:2af9d1c6c6ee | 117 | |
Kilian | 0:2af9d1c6c6ee | 118 | |
Kilian | 0:2af9d1c6c6ee | 119 | |
Kilian | 0:2af9d1c6c6ee | 120 | |
Kilian | 0:2af9d1c6c6ee | 121 | |
Kilian | 0:2af9d1c6c6ee | 122 | |
Kilian | 0:2af9d1c6c6ee | 123 | |
Kilian | 0:2af9d1c6c6ee | 124 | |
Kilian | 0:2af9d1c6c6ee | 125 | |
Kilian | 0:2af9d1c6c6ee | 126 | |
Kilian | 0:2af9d1c6c6ee | 127 | |
Kilian | 0:2af9d1c6c6ee | 128 | |
Kilian | 0:2af9d1c6c6ee | 129 | |
Kilian | 0:2af9d1c6c6ee | 130 | |
Kilian | 0:2af9d1c6c6ee | 131 | |
Kilian | 0:2af9d1c6c6ee | 132 |