Ampel

Dependencies:   mbed

Fork of 2016-01-25_LABOR_Ampel by the new engineer´s

Committer:
tauchi88
Date:
Mon Jan 25 18:49:32 2016 +0000
Revision:
0:b13d29153354
ampel

Who changed what in which revision?

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