Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE EthernetInterface NTPClient SDFileSystem mbed-rtos mbed wave_player
Fork of 2036lab7_template by
TMP36.h@1:a5f43fb83aca, 2018-10-25 (annotated)
- Committer:
- baaosen
- Date:
- Thu Oct 25 14:46:07 2018 +0000
- Revision:
- 1:a5f43fb83aca
- Parent:
- 0:df4d7c0a1594
ECE 2036 project
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 | } |
