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.
Dependents: Mytemperature_Motion
TMP36.h@1:8ac70785ed9b, 2019-04-21 (annotated)
- Committer:
- sharifdeens
- Date:
- Sun Apr 21 03:28:54 2019 +0000
- Revision:
- 1:8ac70785ed9b
- Parent:
- 0:ab3d7d0c34ce
revise
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| zchen311 | 0:ab3d7d0c34ce | 1 | #include "mbed.h" |
| zchen311 | 0:ab3d7d0c34ce | 2 | |
| zchen311 | 0:ab3d7d0c34ce | 3 | //Setup a new class for TMP36 sensor |
| zchen311 | 0:ab3d7d0c34ce | 4 | class TMP36 |
| zchen311 | 0:ab3d7d0c34ce | 5 | { |
| zchen311 | 0:ab3d7d0c34ce | 6 | public: |
| zchen311 | 0:ab3d7d0c34ce | 7 | TMP36(PinName pin); |
| zchen311 | 0:ab3d7d0c34ce | 8 | TMP36(); |
| zchen311 | 0:ab3d7d0c34ce | 9 | operator float (); |
| zchen311 | 0:ab3d7d0c34ce | 10 | float read(); |
| zchen311 | 0:ab3d7d0c34ce | 11 | private: |
| zchen311 | 0:ab3d7d0c34ce | 12 | //class sets up the AnalogIn pin |
| zchen311 | 0:ab3d7d0c34ce | 13 | AnalogIn _pin; |
| zchen311 | 0:ab3d7d0c34ce | 14 | }; |
| zchen311 | 0:ab3d7d0c34ce | 15 | |
| zchen311 | 0:ab3d7d0c34ce | 16 | TMP36::TMP36(PinName pin) : _pin(pin) |
| zchen311 | 0:ab3d7d0c34ce | 17 | { |
| zchen311 | 0:ab3d7d0c34ce | 18 | // _pin(pin) means pass pin to the AnalogIn constructor |
| zchen311 | 0:ab3d7d0c34ce | 19 | } |
| zchen311 | 0:ab3d7d0c34ce | 20 | |
| zchen311 | 0:ab3d7d0c34ce | 21 | float TMP36::read() |
| zchen311 | 0:ab3d7d0c34ce | 22 | { |
| zchen311 | 0:ab3d7d0c34ce | 23 | //convert sensor reading to temperature in degrees C |
| zchen311 | 0:ab3d7d0c34ce | 24 | return ((_pin.read()*3.3)-0.500)*100.0; |
| sharifdeens | 1:8ac70785ed9b | 25 | // return _pin.read(); |
| sharifdeens | 1:8ac70785ed9b | 26 | // return 10; |
| sharifdeens | 1:8ac70785ed9b | 27 | |
| zchen311 | 0:ab3d7d0c34ce | 28 | } |
| zchen311 | 0:ab3d7d0c34ce | 29 | //overload of float conversion (avoids needing to type .read() in equations) |
| zchen311 | 0:ab3d7d0c34ce | 30 | TMP36::operator float () |
| zchen311 | 0:ab3d7d0c34ce | 31 | { |
| zchen311 | 0:ab3d7d0c34ce | 32 | //convert sensor reading to temperature in degrees C |
| zchen311 | 0:ab3d7d0c34ce | 33 | return ((_pin.read()*3.3)-0.500)*100.0; |
| sharifdeens | 1:8ac70785ed9b | 34 | // return _pin.read(); |
| sharifdeens | 1:8ac70785ed9b | 35 | // return 10; |
| zchen311 | 0:ab3d7d0c34ce | 36 | } |
| zchen311 | 0:ab3d7d0c34ce | 37 |