Fahrradleuchte
Dependencies: mbed
BtnEventM0.h@0:d715cbadd410, 2016-11-16 (annotated)
- Committer:
- david22
- Date:
- Wed Nov 16 10:58:26 2016 +0000
- Revision:
- 0:d715cbadd410
Richtiges Projekt f?r 3CHEL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
david22 | 0:d715cbadd410 | 1 | |
david22 | 0:d715cbadd410 | 2 | |
david22 | 0:d715cbadd410 | 3 | class BtnEventM0 |
david22 | 0:d715cbadd410 | 4 | { |
david22 | 0:d715cbadd410 | 5 | public: |
david22 | 0:d715cbadd410 | 6 | int16_t pressed; |
david22 | 0:d715cbadd410 | 7 | |
david22 | 0:d715cbadd410 | 8 | BtnEventM0(PinName pin) : _isr(pin) { |
david22 | 0:d715cbadd410 | 9 | pressed=0; |
david22 | 0:d715cbadd410 | 10 | } |
david22 | 0:d715cbadd410 | 11 | |
david22 | 0:d715cbadd410 | 12 | // Ist eine steigende Flanke aufgetreten ? |
david22 | 0:d715cbadd410 | 13 | int CheckFlag() { |
david22 | 0:d715cbadd410 | 14 | if( pressed ) { |
david22 | 0:d715cbadd410 | 15 | pressed=0; |
david22 | 0:d715cbadd410 | 16 | return 1; |
david22 | 0:d715cbadd410 | 17 | } |
david22 | 0:d715cbadd410 | 18 | return 0; |
david22 | 0:d715cbadd410 | 19 | } |
david22 | 0:d715cbadd410 | 20 | |
david22 | 0:d715cbadd410 | 21 | // 1..Button is pressed else 0 |
david22 | 0:d715cbadd410 | 22 | int CheckButton() { |
david22 | 0:d715cbadd410 | 23 | return _isr.read(); |
david22 | 0:d715cbadd410 | 24 | } |
david22 | 0:d715cbadd410 | 25 | |
david22 | 0:d715cbadd410 | 26 | void Init() { |
david22 | 0:d715cbadd410 | 27 | _isr.rise(this, &BtnEventM0::RisingISR); |
david22 | 0:d715cbadd410 | 28 | } |
david22 | 0:d715cbadd410 | 29 | |
david22 | 0:d715cbadd410 | 30 | void RisingISR() { |
david22 | 0:d715cbadd410 | 31 | if( _isr.read() ) |
david22 | 0:d715cbadd410 | 32 | pressed = 1; |
david22 | 0:d715cbadd410 | 33 | } |
david22 | 0:d715cbadd410 | 34 | protected: |
david22 | 0:d715cbadd410 | 35 | InterruptIn _isr; |
david22 | 0:d715cbadd410 | 36 | }; |
david22 | 0:d715cbadd410 | 37 | |
david22 | 0:d715cbadd410 | 38 | /* |
david22 | 0:d715cbadd410 | 39 | class BtnEventM02 : public BtnEventM0 |
david22 | 0:d715cbadd410 | 40 | { |
david22 | 0:d715cbadd410 | 41 | public: |
david22 | 0:d715cbadd410 | 42 | BtnEventM02(PinName pin) : BtnEventM0(pin) { |
david22 | 0:d715cbadd410 | 43 | _tm.stop(); |
david22 | 0:d715cbadd410 | 44 | _tm.reset(); |
david22 | 0:d715cbadd410 | 45 | _state=1; |
david22 | 0:d715cbadd410 | 46 | } |
david22 | 0:d715cbadd410 | 47 | |
david22 | 0:d715cbadd410 | 48 | void Init() { |
david22 | 0:d715cbadd410 | 49 | _isr.rise(this, &BtnEventM02::RisingISR); |
david22 | 0:d715cbadd410 | 50 | } |
david22 | 0:d715cbadd410 | 51 | |
david22 | 0:d715cbadd410 | 52 | void RisingISR() { |
david22 | 0:d715cbadd410 | 53 | if( !_isr.read() ) |
david22 | 0:d715cbadd410 | 54 | return; |
david22 | 0:d715cbadd410 | 55 | pressed = 1; |
david22 | 0:d715cbadd410 | 56 | _tm.start(); |
david22 | 0:d715cbadd410 | 57 | _state = 2; |
david22 | 0:d715cbadd410 | 58 | } |
david22 | 0:d715cbadd410 | 59 | |
david22 | 0:d715cbadd410 | 60 | void CheckButton() { |
david22 | 0:d715cbadd410 | 61 | if( _state==1 ) |
david22 | 0:d715cbadd410 | 62 | return; |
david22 | 0:d715cbadd410 | 63 | if( _state==2 ) { |
david22 | 0:d715cbadd410 | 64 | if( !_isr.read() ) { |
david22 | 0:d715cbadd410 | 65 | _state = 1; |
david22 | 0:d715cbadd410 | 66 | return; |
david22 | 0:d715cbadd410 | 67 | } |
david22 | 0:d715cbadd410 | 68 | if( _tm.read_ms()>500 ) { |
david22 | 0:d715cbadd410 | 69 | _tm.reset(); |
david22 | 0:d715cbadd410 | 70 | _state = 3; |
david22 | 0:d715cbadd410 | 71 | pressed = 1; |
david22 | 0:d715cbadd410 | 72 | } |
david22 | 0:d715cbadd410 | 73 | } else if( _state==3 ) { |
david22 | 0:d715cbadd410 | 74 | if( !_isr.read() ) { |
david22 | 0:d715cbadd410 | 75 | _state = 1; |
david22 | 0:d715cbadd410 | 76 | return; |
david22 | 0:d715cbadd410 | 77 | } |
david22 | 0:d715cbadd410 | 78 | if( _tm.read_ms()>100 ) { |
david22 | 0:d715cbadd410 | 79 | _tm.reset(); |
david22 | 0:d715cbadd410 | 80 | _state = 3; |
david22 | 0:d715cbadd410 | 81 | pressed = 1; |
david22 | 0:d715cbadd410 | 82 | } |
david22 | 0:d715cbadd410 | 83 | } |
david22 | 0:d715cbadd410 | 84 | } |
david22 | 0:d715cbadd410 | 85 | private: |
david22 | 0:d715cbadd410 | 86 | int16_t _state; |
david22 | 0:d715cbadd410 | 87 | Timer _tm; |
david22 | 0:d715cbadd410 | 88 | }; |
david22 | 0:d715cbadd410 | 89 | */ |
david22 | 0:d715cbadd410 | 90 | |
david22 | 0:d715cbadd410 | 91 | class AnalogInHL : public AnalogIn |
david22 | 0:d715cbadd410 | 92 | { |
david22 | 0:d715cbadd410 | 93 | public: |
david22 | 0:d715cbadd410 | 94 | AnalogInHL(PinName pin) : AnalogIn(pin) { } |
david22 | 0:d715cbadd410 | 95 | int Read() { |
david22 | 0:d715cbadd410 | 96 | return read_u16()>>6; |
david22 | 0:d715cbadd410 | 97 | } |
david22 | 0:d715cbadd410 | 98 | }; |
david22 | 0:d715cbadd410 | 99 | |
david22 | 0:d715cbadd410 | 100 | |
david22 | 0:d715cbadd410 | 101 | |
david22 | 0:d715cbadd410 | 102 | |
david22 | 0:d715cbadd410 | 103 | |
david22 | 0:d715cbadd410 | 104 | |
david22 | 0:d715cbadd410 | 105 | |
david22 | 0:d715cbadd410 | 106 | |
david22 | 0:d715cbadd410 | 107 | |
david22 | 0:d715cbadd410 | 108 | |
david22 | 0:d715cbadd410 | 109 | |
david22 | 0:d715cbadd410 | 110 | |
david22 | 0:d715cbadd410 | 111 | |
david22 | 0:d715cbadd410 | 112 | |
david22 | 0:d715cbadd410 | 113 | |
david22 | 0:d715cbadd410 | 114 | |
david22 | 0:d715cbadd410 | 115 | |
david22 | 0:d715cbadd410 | 116 | |
david22 | 0:d715cbadd410 | 117 | |
david22 | 0:d715cbadd410 | 118 | |
david22 | 0:d715cbadd410 | 119 | |
david22 | 0:d715cbadd410 | 120 | |
david22 | 0:d715cbadd410 | 121 | |
david22 | 0:d715cbadd410 | 122 | |
david22 | 0:d715cbadd410 | 123 | |
david22 | 0:d715cbadd410 | 124 | |
david22 | 0:d715cbadd410 | 125 | |
david22 | 0:d715cbadd410 | 126 | |
david22 | 0:d715cbadd410 | 127 | |
david22 | 0:d715cbadd410 | 128 | |
david22 | 0:d715cbadd410 | 129 | |
david22 | 0:d715cbadd410 | 130 | |
david22 | 0:d715cbadd410 | 131 | |
david22 | 0:d715cbadd410 | 132 | |
david22 | 0:d715cbadd410 | 133 | |
david22 | 0:d715cbadd410 | 134 | |
david22 | 0:d715cbadd410 | 135 | |
david22 | 0:d715cbadd410 | 136 | |
david22 | 0:d715cbadd410 | 137 | |
david22 | 0:d715cbadd410 | 138 | |
david22 | 0:d715cbadd410 | 139 | |
david22 | 0:d715cbadd410 | 140 | |
david22 | 0:d715cbadd410 | 141 | |
david22 | 0:d715cbadd410 | 142 | |
david22 | 0:d715cbadd410 | 143 | |
david22 | 0:d715cbadd410 | 144 | |
david22 | 0:d715cbadd410 | 145 | |
david22 | 0:d715cbadd410 | 146 |