template
Dependencies: 4DGL-uLCD-SE EthernetInterface NTPClient SDFileSystem mbed-rtos mbed wave_player
Fork of 2036lab7_template by
TMP36.h@1:2a0dea19d2ba, 2016-02-01 (annotated)
- Committer:
- ssong86
- Date:
- Mon Feb 01 06:41:04 2016 +0000
- Revision:
- 1:2a0dea19d2ba
- Parent:
- 0:df4d7c0a1594
template
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:df4d7c0a1594 | 1 | #include "mbed.h" |
4180_1 | 0:df4d7c0a1594 | 2 | |
4180_1 | 0:df4d7c0a1594 | 3 | //Setup a new class for TMP36 sensor |
4180_1 | 0:df4d7c0a1594 | 4 | class TMP36 |
4180_1 | 0:df4d7c0a1594 | 5 | { |
4180_1 | 0:df4d7c0a1594 | 6 | public: |
4180_1 | 0:df4d7c0a1594 | 7 | TMP36(PinName pin); |
4180_1 | 0:df4d7c0a1594 | 8 | TMP36(); |
4180_1 | 0:df4d7c0a1594 | 9 | operator float (); |
4180_1 | 0:df4d7c0a1594 | 10 | float read(); |
4180_1 | 0:df4d7c0a1594 | 11 | private: |
4180_1 | 0:df4d7c0a1594 | 12 | //class sets up the AnalogIn pin |
4180_1 | 0:df4d7c0a1594 | 13 | AnalogIn _pin; |
4180_1 | 0:df4d7c0a1594 | 14 | }; |
4180_1 | 0:df4d7c0a1594 | 15 | |
4180_1 | 0:df4d7c0a1594 | 16 | TMP36::TMP36(PinName pin) : _pin(pin) |
4180_1 | 0:df4d7c0a1594 | 17 | { |
4180_1 | 0:df4d7c0a1594 | 18 | // _pin(pin) means pass pin to the AnalogIn constructor |
4180_1 | 0:df4d7c0a1594 | 19 | } |
4180_1 | 0:df4d7c0a1594 | 20 | |
4180_1 | 0:df4d7c0a1594 | 21 | float TMP36::read() |
4180_1 | 0:df4d7c0a1594 | 22 | { |
4180_1 | 0:df4d7c0a1594 | 23 | //convert sensor reading to temperature in degrees C |
4180_1 | 0:df4d7c0a1594 | 24 | return ((_pin.read()*3.3)-0.500)*100.0; |
4180_1 | 0:df4d7c0a1594 | 25 | } |
4180_1 | 0:df4d7c0a1594 | 26 | //overload of float conversion (avoids needing to type .read() in equations) |
4180_1 | 0:df4d7c0a1594 | 27 | TMP36::operator float () |
4180_1 | 0:df4d7c0a1594 | 28 | { |
4180_1 | 0:df4d7c0a1594 | 29 | //convert sensor reading to temperature in degrees C |
4180_1 | 0:df4d7c0a1594 | 30 | return ((_pin.read()*3.3)-0.500)*100.0; |
4180_1 | 0:df4d7c0a1594 | 31 | } |