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