123
Dependencies: WS2812 PixelArray DebounceIn
sensor.h@0:ea88f8c194d2, 2020-06-24 (annotated)
- Committer:
- turumputum
- Date:
- Wed Jun 24 12:41:45 2020 +0000
- Revision:
- 0:ea88f8c194d2
good for me
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
turumputum | 0:ea88f8c194d2 | 1 | #include "mbed.h" |
turumputum | 0:ea88f8c194d2 | 2 | //#include "main.h" |
turumputum | 0:ea88f8c194d2 | 3 | |
turumputum | 0:ea88f8c194d2 | 4 | #define PERIOD 1000 |
turumputum | 0:ea88f8c194d2 | 5 | |
turumputum | 0:ea88f8c194d2 | 6 | extern int report; |
turumputum | 0:ea88f8c194d2 | 7 | extern uint8_t tableState[4][30]; |
turumputum | 0:ea88f8c194d2 | 8 | |
turumputum | 0:ea88f8c194d2 | 9 | class Sensor: public DigitalIn |
turumputum | 0:ea88f8c194d2 | 10 | { |
turumputum | 0:ea88f8c194d2 | 11 | public: |
turumputum | 0:ea88f8c194d2 | 12 | |
turumputum | 0:ea88f8c194d2 | 13 | Sensor (PinName pin, int i) : DigitalIn(pin), placeInTable(i) // create the InterruptIn on the pin specified to Counter |
turumputum | 0:ea88f8c194d2 | 14 | { |
turumputum | 0:ea88f8c194d2 | 15 | DigitalIn::mode(PullDown); |
turumputum | 0:ea88f8c194d2 | 16 | _samples = 10; |
turumputum | 0:ea88f8c194d2 | 17 | _ticker.attach_us(this, &Sensor::_callback, PERIOD); |
turumputum | 0:ea88f8c194d2 | 18 | _counter = 0; |
turumputum | 0:ea88f8c194d2 | 19 | //_interrupt.rise(callback(this, &Sensor::increment)); // attach increment function of this counter instance |
turumputum | 0:ea88f8c194d2 | 20 | } |
turumputum | 0:ea88f8c194d2 | 21 | |
turumputum | 0:ea88f8c194d2 | 22 | |
turumputum | 0:ea88f8c194d2 | 23 | protected: |
turumputum | 0:ea88f8c194d2 | 24 | |
turumputum | 0:ea88f8c194d2 | 25 | Ticker _ticker; |
turumputum | 0:ea88f8c194d2 | 26 | //InterruptIn _interrupt; |
turumputum | 0:ea88f8c194d2 | 27 | int placeInTable; |
turumputum | 0:ea88f8c194d2 | 28 | int _shadow; |
turumputum | 0:ea88f8c194d2 | 29 | int _counter; |
turumputum | 0:ea88f8c194d2 | 30 | int _samples; |
turumputum | 0:ea88f8c194d2 | 31 | |
turumputum | 0:ea88f8c194d2 | 32 | void _callback(void) |
turumputum | 0:ea88f8c194d2 | 33 | { |
turumputum | 0:ea88f8c194d2 | 34 | if (DigitalIn::read()) { |
turumputum | 0:ea88f8c194d2 | 35 | if (_counter < _samples) _counter++; |
turumputum | 0:ea88f8c194d2 | 36 | if (_counter >=_samples) { |
turumputum | 0:ea88f8c194d2 | 37 | _shadow = 1; |
turumputum | 0:ea88f8c194d2 | 38 | if(_counter < (_samples+5))_counter++; |
turumputum | 0:ea88f8c194d2 | 39 | if(tableState[1][placeInTable]==0){report=1;} |
turumputum | 0:ea88f8c194d2 | 40 | tableState[1][placeInTable]=1; |
turumputum | 0:ea88f8c194d2 | 41 | |
turumputum | 0:ea88f8c194d2 | 42 | } |
turumputum | 0:ea88f8c194d2 | 43 | |
turumputum | 0:ea88f8c194d2 | 44 | } else { |
turumputum | 0:ea88f8c194d2 | 45 | if (_counter > 0) _counter--; |
turumputum | 0:ea88f8c194d2 | 46 | if (_counter == 0) { |
turumputum | 0:ea88f8c194d2 | 47 | _shadow = 0; |
turumputum | 0:ea88f8c194d2 | 48 | if(tableState[1][placeInTable]==1){report=1;} |
turumputum | 0:ea88f8c194d2 | 49 | tableState[1][placeInTable]=0; |
turumputum | 0:ea88f8c194d2 | 50 | |
turumputum | 0:ea88f8c194d2 | 51 | } |
turumputum | 0:ea88f8c194d2 | 52 | } |
turumputum | 0:ea88f8c194d2 | 53 | } |
turumputum | 0:ea88f8c194d2 | 54 | |
turumputum | 0:ea88f8c194d2 | 55 | |
turumputum | 0:ea88f8c194d2 | 56 | |
turumputum | 0:ea88f8c194d2 | 57 | }; |
turumputum | 0:ea88f8c194d2 | 58 | |
turumputum | 0:ea88f8c194d2 | 59 | |
turumputum | 0:ea88f8c194d2 | 60 | //__________SENSOR DEFINE___________________ |
turumputum | 0:ea88f8c194d2 | 61 | |
turumputum | 0:ea88f8c194d2 | 62 | |
turumputum | 0:ea88f8c194d2 | 63 | Sensor Stenka_y1(PB_2,0); |
turumputum | 0:ea88f8c194d2 | 64 | Sensor Stenka_c2(PB_14,1); |
turumputum | 0:ea88f8c194d2 | 65 | Sensor Stenka_c3(PA_3,2); |
turumputum | 0:ea88f8c194d2 | 66 | Sensor Stenka_y4(PB_4,3); |
turumputum | 0:ea88f8c194d2 | 67 | Sensor Stenka_c5(PA_6,4); |
turumputum | 0:ea88f8c194d2 | 68 | Sensor Stenka_y6(PC_8,5); |
turumputum | 0:ea88f8c194d2 | 69 | Sensor Stenka_c7(PA_15,6); |
turumputum | 0:ea88f8c194d2 | 70 | Sensor Stenka_c8(PC_7,7); |
turumputum | 0:ea88f8c194d2 | 71 | Sensor Stenka_y9(PB_6,8); |
turumputum | 0:ea88f8c194d2 | 72 | Sensor Stenka_c10(PB_1,9); |
turumputum | 0:ea88f8c194d2 | 73 | |
turumputum | 0:ea88f8c194d2 | 74 | Sensor Membrana_y1(PC_0,10); |
turumputum | 0:ea88f8c194d2 | 75 | Sensor Membrana_c2(PB_8,11); |
turumputum | 0:ea88f8c194d2 | 76 | Sensor Membrana_c3(PB_9 ,12); |
turumputum | 0:ea88f8c194d2 | 77 | Sensor Membrana_y4(PC_2,13); |
turumputum | 0:ea88f8c194d2 | 78 | Sensor Membrana_c5(PB_10,14); |
turumputum | 0:ea88f8c194d2 | 79 | Sensor Membrana_y6(PC_3,15); |
turumputum | 0:ea88f8c194d2 | 80 | Sensor Membrana_c7(PB_11,16); |
turumputum | 0:ea88f8c194d2 | 81 | Sensor Membrana_c8(PB_12,17); |
turumputum | 0:ea88f8c194d2 | 82 | Sensor Membrana_y9(PC_6,18); |
turumputum | 0:ea88f8c194d2 | 83 | Sensor Membrana_c10(PB_15,19); |
turumputum | 0:ea88f8c194d2 | 84 | |
turumputum | 0:ea88f8c194d2 | 85 | Sensor Lizosoma(PC_9,25); |
turumputum | 0:ea88f8c194d2 | 86 | Sensor Vacuol(PC_10,24); |
turumputum | 0:ea88f8c194d2 | 87 | Sensor Yadro(PC_11,20); |
turumputum | 0:ea88f8c194d2 | 88 | Sensor Nucleoid(PC_12,29); |
turumputum | 0:ea88f8c194d2 | 89 | Sensor Mitohondriya(PD_0,21); |
turumputum | 0:ea88f8c194d2 | 90 | Sensor Ribosoma(PD_1,28); |
turumputum | 0:ea88f8c194d2 | 91 | Sensor Goldgi(PD_2,26); |
turumputum | 0:ea88f8c194d2 | 92 | Sensor Plastida(PD_3,23); |
turumputum | 0:ea88f8c194d2 | 93 | Sensor Centor(PD_4,27); |
turumputum | 0:ea88f8c194d2 | 94 | Sensor Endoplazma(PD_5,22); |