simple temperature sensor
Dependents: HARP2 HARP3 Thermostat_NucleoF401 4180Lab4_p1 ... more
TMP36GZ.h@3:84ed914fb203, 2012-09-20 (annotated)
- Committer:
- tylerjw
- Date:
- Thu Sep 20 23:22:22 2012 +0000
- Revision:
- 3:84ed914fb203
- Parent:
- 2:c368493b71a9
- Child:
- 5:dd80dac0124c
0.4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tylerjw | 3:84ed914fb203 | 1 | /* |
tylerjw | 0:2bfb76da015b | 2 | * @author Tyler Weaver |
tylerjw | 0:2bfb76da015b | 3 | * |
tylerjw | 0:2bfb76da015b | 4 | * @section LICENSE |
tylerjw | 0:2bfb76da015b | 5 | * |
tylerjw | 0:2bfb76da015b | 6 | * Copyright (c) 2012 Tyler Weaver, MIT License |
tylerjw | 0:2bfb76da015b | 7 | * |
tylerjw | 0:2bfb76da015b | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
tylerjw | 0:2bfb76da015b | 9 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
tylerjw | 0:2bfb76da015b | 10 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
tylerjw | 0:2bfb76da015b | 11 | |
tylerjw | 0:2bfb76da015b | 12 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
tylerjw | 0:2bfb76da015b | 13 | * furnished to do so, subject to the following conditions: |
tylerjw | 0:2bfb76da015b | 14 | * |
tylerjw | 0:2bfb76da015b | 15 | * The above copyright notice and this permission notice shall be included in all copies or |
tylerjw | 0:2bfb76da015b | 16 | * substantial portions of the Software. |
tylerjw | 0:2bfb76da015b | 17 | * |
tylerjw | 0:2bfb76da015b | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
tylerjw | 0:2bfb76da015b | 19 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
tylerjw | 0:2bfb76da015b | 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
tylerjw | 0:2bfb76da015b | 21 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
tylerjw | 0:2bfb76da015b | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
tylerjw | 0:2bfb76da015b | 23 | * |
tylerjw | 0:2bfb76da015b | 24 | * @section DESCRIPTION |
tylerjw | 0:2bfb76da015b | 25 | * |
tylerjw | 0:2bfb76da015b | 26 | * Header file for TMP36GZ temperature sensor library |
tylerjw | 0:2bfb76da015b | 27 | * |
tylerjw | 0:2bfb76da015b | 28 | * /----\ |
tylerjw | 0:2bfb76da015b | 29 | * |1 2 3 | |
tylerjw | 3:84ed914fb203 | 30 | * |
tylerjw | 0:2bfb76da015b | 31 | * 1 - Vs, connect 3.3V (Vout) |
tylerjw | 0:2bfb76da015b | 32 | * 2 - Vout - connect to input pin |
tylerjw | 0:2bfb76da015b | 33 | * 3 - GND - connect to ground |
tylerjw | 0:2bfb76da015b | 34 | * |
tylerjw | 0:2bfb76da015b | 35 | * 100mV -40 deg/C |
tylerjw | 0:2bfb76da015b | 36 | * 500mV 0 deg/C |
tylerjw | 0:2bfb76da015b | 37 | * 750mV 25 deg/C |
tylerjw | 0:2bfb76da015b | 38 | *2000mV 125 deg/C |
tylerjw | 0:2bfb76da015b | 39 | * |
tylerjw | 0:2bfb76da015b | 40 | * 10mV / deg/C |
tylerjw | 0:2bfb76da015b | 41 | */ |
tylerjw | 0:2bfb76da015b | 42 | #include "mbed.h" |
tylerjw | 0:2bfb76da015b | 43 | |
tylerjw | 3:84ed914fb203 | 44 | /** TMP36GZ temperature sensor class |
tylerjw | 0:2bfb76da015b | 45 | * |
tylerjw | 0:2bfb76da015b | 46 | * Example: |
tylerjw | 0:2bfb76da015b | 47 | * @code |
tylerjw | 3:84ed914fb203 | 48 | * #include "mbed.h" |
tylerjw | 3:84ed914fb203 | 49 | * #include "TMP36GZ.h" |
tylerjw | 3:84ed914fb203 | 50 | * |
tylerjw | 3:84ed914fb203 | 51 | * TMP36GZ temp_sensor(p20); |
tylerjw | 3:84ed914fb203 | 52 | * Serial pc(USBTX, USBRX); // tx, rx |
tylerjw | 3:84ed914fb203 | 53 | * |
tylerjw | 3:84ed914fb203 | 54 | * int main() { |
tylerjw | 3:84ed914fb203 | 55 | * pc.baud(9600); |
tylerjw | 3:84ed914fb203 | 56 | * while(1) { |
tylerjw | 3:84ed914fb203 | 57 | * pc.printf("Temp: %6.3f deg/C - %6.3f deg/F\n", temp_sensor.sample(), temp_sensor.sample_f()); |
tylerjw | 3:84ed914fb203 | 58 | * wait(1.0); // wait 1 second |
tylerjw | 3:84ed914fb203 | 59 | * } |
tylerjw | 3:84ed914fb203 | 60 | * } |
tylerjw | 0:2bfb76da015b | 61 | * @endcode |
tylerjw | 0:2bfb76da015b | 62 | */ |
tylerjw | 0:2bfb76da015b | 63 | |
tylerjw | 0:2bfb76da015b | 64 | class TMP36GZ |
tylerjw | 0:2bfb76da015b | 65 | { |
tylerjw | 0:2bfb76da015b | 66 | public: |
tylerjw | 3:84ed914fb203 | 67 | /** Constructor for TMP36GZ sensor |
tylerjw | 0:2bfb76da015b | 68 | * |
tylerjw | 0:2bfb76da015b | 69 | * Analog input pin from p15-p20 |
tylerjw | 0:2bfb76da015b | 70 | * |
tylerjw | 0:2bfb76da015b | 71 | * @param pin the analog input pin (connect to pin 2 on sensor) |
tylerjw | 0:2bfb76da015b | 72 | */ |
tylerjw | 0:2bfb76da015b | 73 | TMP36GZ(PinName pin); |
tylerjw | 3:84ed914fb203 | 74 | |
tylerjw | 3:84ed914fb203 | 75 | /** Sample the sensor in deg C |
tylerjw | 0:2bfb76da015b | 76 | * |
tylerjw | 0:2bfb76da015b | 77 | * @returns float value in deg C |
tylerjw | 0:2bfb76da015b | 78 | */ |
tylerjw | 0:2bfb76da015b | 79 | float sample(); |
tylerjw | 3:84ed914fb203 | 80 | |
tylerjw | 3:84ed914fb203 | 81 | /** Sample the sensor in deg F |
tylerjw | 0:2bfb76da015b | 82 | * |
tylerjw | 0:2bfb76da015b | 83 | * @returns float value in deg F |
tylerjw | 0:2bfb76da015b | 84 | */ |
tylerjw | 0:2bfb76da015b | 85 | float sample_f(); |
tylerjw | 3:84ed914fb203 | 86 | |
tylerjw | 3:84ed914fb203 | 87 | private: |
tylerjw | 3:84ed914fb203 | 88 | AnalogIn *input_pin_; |
tylerjw | 0:2bfb76da015b | 89 | }; |