simple temperature sensor
Dependents: HARP2 HARP3 Thermostat_NucleoF401 4180Lab4_p1 ... more
TMP36GZ.h@7:9a916a3a059f, 2012-09-20 (annotated)
- Committer:
- tylerjw
- Date:
- Thu Sep 20 23:32:12 2012 +0000
- Revision:
- 7:9a916a3a059f
- Parent:
- 6:03535a37f125
- Child:
- 8:2b0feb7bdebc
0.8
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 | 0:2bfb76da015b | 43 | */ |
tylerjw | 0:2bfb76da015b | 44 | |
tylerjw | 0:2bfb76da015b | 45 | class TMP36GZ |
tylerjw | 0:2bfb76da015b | 46 | { |
tylerjw | 0:2bfb76da015b | 47 | public: |
tylerjw | 3:84ed914fb203 | 48 | /** Constructor for TMP36GZ sensor |
tylerjw | 0:2bfb76da015b | 49 | * |
tylerjw | 0:2bfb76da015b | 50 | * Analog input pin from p15-p20 |
tylerjw | 0:2bfb76da015b | 51 | * |
tylerjw | 0:2bfb76da015b | 52 | * @param pin the analog input pin (connect to pin 2 on sensor) |
tylerjw | 0:2bfb76da015b | 53 | */ |
tylerjw | 0:2bfb76da015b | 54 | TMP36GZ(PinName pin); |
tylerjw | 3:84ed914fb203 | 55 | |
tylerjw | 3:84ed914fb203 | 56 | /** Sample the sensor in deg C |
tylerjw | 0:2bfb76da015b | 57 | * |
tylerjw | 0:2bfb76da015b | 58 | * @returns float value in deg C |
tylerjw | 0:2bfb76da015b | 59 | */ |
tylerjw | 0:2bfb76da015b | 60 | float sample(); |
tylerjw | 3:84ed914fb203 | 61 | |
tylerjw | 3:84ed914fb203 | 62 | /** Sample the sensor in deg F |
tylerjw | 0:2bfb76da015b | 63 | * |
tylerjw | 0:2bfb76da015b | 64 | * @returns float value in deg F |
tylerjw | 0:2bfb76da015b | 65 | */ |
tylerjw | 0:2bfb76da015b | 66 | float sample_f(); |
tylerjw | 3:84ed914fb203 | 67 | |
tylerjw | 3:84ed914fb203 | 68 | private: |
tylerjw | 3:84ed914fb203 | 69 | AnalogIn *input_pin_; |
tylerjw | 0:2bfb76da015b | 70 | }; |