read LDR sensor
Dependents: Mytemperature_Motion
LDR_sensor.h@0:b6b6c41a37e6, 2019-04-21 (annotated)
- Committer:
- sharifdeens
- Date:
- Sun Apr 21 03:29:41 2019 +0000
- Revision:
- 0:b6b6c41a37e6
ldr
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sharifdeens | 0:b6b6c41a37e6 | 1 | #include "mbed.h" |
sharifdeens | 0:b6b6c41a37e6 | 2 | |
sharifdeens | 0:b6b6c41a37e6 | 3 | //Sensor new class for sensorA |
sharifdeens | 0:b6b6c41a37e6 | 4 | class LDR_sensor |
sharifdeens | 0:b6b6c41a37e6 | 5 | |
sharifdeens | 0:b6b6c41a37e6 | 6 | { |
sharifdeens | 0:b6b6c41a37e6 | 7 | public: |
sharifdeens | 0:b6b6c41a37e6 | 8 | |
sharifdeens | 0:b6b6c41a37e6 | 9 | LDR_sensor(PinName pin2); |
sharifdeens | 0:b6b6c41a37e6 | 10 | LDR_sensor(); |
sharifdeens | 0:b6b6c41a37e6 | 11 | operator float (); |
sharifdeens | 0:b6b6c41a37e6 | 12 | float read(); |
sharifdeens | 0:b6b6c41a37e6 | 13 | private: |
sharifdeens | 0:b6b6c41a37e6 | 14 | //class sets up the AnalogIn pin |
sharifdeens | 0:b6b6c41a37e6 | 15 | AnalogIn _pin2; |
sharifdeens | 0:b6b6c41a37e6 | 16 | }; |
sharifdeens | 0:b6b6c41a37e6 | 17 | |
sharifdeens | 0:b6b6c41a37e6 | 18 | |
sharifdeens | 0:b6b6c41a37e6 | 19 | LDR_sensor::LDR_sensor(PinName pin2) : _pin2(pin2) |
sharifdeens | 0:b6b6c41a37e6 | 20 | { |
sharifdeens | 0:b6b6c41a37e6 | 21 | // _pin(pin) means pass pin to the AnalogIn constructor |
sharifdeens | 0:b6b6c41a37e6 | 22 | } |
sharifdeens | 0:b6b6c41a37e6 | 23 | |
sharifdeens | 0:b6b6c41a37e6 | 24 | float LDR_sensor::read() |
sharifdeens | 0:b6b6c41a37e6 | 25 | |
sharifdeens | 0:b6b6c41a37e6 | 26 | { |
sharifdeens | 0:b6b6c41a37e6 | 27 | //read moisture sensor |
sharifdeens | 0:b6b6c41a37e6 | 28 | return _pin2.read(); |
sharifdeens | 0:b6b6c41a37e6 | 29 | } |
sharifdeens | 0:b6b6c41a37e6 | 30 | |
sharifdeens | 0:b6b6c41a37e6 | 31 | LDR_sensor::operator float () |
sharifdeens | 0:b6b6c41a37e6 | 32 | { |
sharifdeens | 0:b6b6c41a37e6 | 33 | //convert sensor reading to temperature in degrees C |
sharifdeens | 0:b6b6c41a37e6 | 34 | return _pin2.read(); |
sharifdeens | 0:b6b6c41a37e6 | 35 | } |