AC with Bluetooth Control
Dependencies: 4DGL-uLCD-SE mbed-rtos mbed
TMP36.h@0:d185280d778b, 2017-03-14 (annotated)
- Committer:
- fmaxwell6
- Date:
- Tue Mar 14 19:26:45 2017 +0000
- Revision:
- 0:d185280d778b
AC controlled with bluetooth
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fmaxwell6 | 0:d185280d778b | 1 | #include "mbed.h" |
fmaxwell6 | 0:d185280d778b | 2 | |
fmaxwell6 | 0:d185280d778b | 3 | //Setup a new class for TMP36 sensor |
fmaxwell6 | 0:d185280d778b | 4 | class TMP36 |
fmaxwell6 | 0:d185280d778b | 5 | { |
fmaxwell6 | 0:d185280d778b | 6 | public: |
fmaxwell6 | 0:d185280d778b | 7 | TMP36(PinName pin); |
fmaxwell6 | 0:d185280d778b | 8 | TMP36(); |
fmaxwell6 | 0:d185280d778b | 9 | operator float (); |
fmaxwell6 | 0:d185280d778b | 10 | float read(); |
fmaxwell6 | 0:d185280d778b | 11 | private: |
fmaxwell6 | 0:d185280d778b | 12 | //class sets up the AnalogIn pin |
fmaxwell6 | 0:d185280d778b | 13 | AnalogIn _pin; |
fmaxwell6 | 0:d185280d778b | 14 | }; |
fmaxwell6 | 0:d185280d778b | 15 | |
fmaxwell6 | 0:d185280d778b | 16 | TMP36::TMP36(PinName pin) : _pin(pin) |
fmaxwell6 | 0:d185280d778b | 17 | { |
fmaxwell6 | 0:d185280d778b | 18 | // _pin(pin) means pass pin to the AnalogIn constructor |
fmaxwell6 | 0:d185280d778b | 19 | } |
fmaxwell6 | 0:d185280d778b | 20 | |
fmaxwell6 | 0:d185280d778b | 21 | float TMP36::read() |
fmaxwell6 | 0:d185280d778b | 22 | { |
fmaxwell6 | 0:d185280d778b | 23 | //convert sensor reading to temperature in degrees C |
fmaxwell6 | 0:d185280d778b | 24 | return ((_pin.read()*3.3)-0.500)*100.0; |
fmaxwell6 | 0:d185280d778b | 25 | } |
fmaxwell6 | 0:d185280d778b | 26 | //overload of float conversion (avoids needing to type .read() in equations) |
fmaxwell6 | 0:d185280d778b | 27 | TMP36::operator float () |
fmaxwell6 | 0:d185280d778b | 28 | { |
fmaxwell6 | 0:d185280d778b | 29 | //convert sensor reading to temperature in degrees C |
fmaxwell6 | 0:d185280d778b | 30 | return ((_pin.read()*3.3)-0.500)*100.0; |
fmaxwell6 | 0:d185280d778b | 31 | } |