simple temperature sensor

Dependents:   HARP2 HARP3 Thermostat_NucleoF401 4180Lab4_p1 ... more

Committer:
tylerjw
Date:
Thu Sep 20 23:16:13 2012 +0000
Revision:
1:01194600336b
Parent:
0:2bfb76da015b
Child:
2:c368493b71a9
0.2 fixed documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tylerjw 1:01194600336b 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 0:2bfb76da015b 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 0:2bfb76da015b 44 /** TMP36GZ temperature sensor
tylerjw 0:2bfb76da015b 45 *
tylerjw 0:2bfb76da015b 46 * Example:
tylerjw 0:2bfb76da015b 47 * @code
tylerjw 0:2bfb76da015b 48 #include "mbed.h"
tylerjw 0:2bfb76da015b 49 #include "TMP36GZ.h"
tylerjw 0:2bfb76da015b 50
tylerjw 0:2bfb76da015b 51 TMP36GZ temp_sensor(p20);
tylerjw 0:2bfb76da015b 52 Serial pc(USBTX, USBRX); // tx, rx
tylerjw 0:2bfb76da015b 53
tylerjw 0:2bfb76da015b 54 int main() {
tylerjw 0:2bfb76da015b 55 pc.baud(9600);
tylerjw 0:2bfb76da015b 56 while(1) {
tylerjw 0:2bfb76da015b 57 pc.printf("Temp: %6.3f deg/C - %6.3f deg/F\n", temp_sensor.sample(), temp_sensor.sample_f());
tylerjw 0:2bfb76da015b 58 wait(1.0); // wait 1 second
tylerjw 0:2bfb76da015b 59 }
tylerjw 0:2bfb76da015b 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 private:
tylerjw 0:2bfb76da015b 67 AnalogIn *input_pin_;
tylerjw 0:2bfb76da015b 68
tylerjw 0:2bfb76da015b 69 public:
tylerjw 0:2bfb76da015b 70
tylerjw 0:2bfb76da015b 71 /** Constructor for TMP36GZ sensor
tylerjw 0:2bfb76da015b 72 *
tylerjw 0:2bfb76da015b 73 * Analog input pin from p15-p20
tylerjw 0:2bfb76da015b 74 *
tylerjw 0:2bfb76da015b 75 * @param pin the analog input pin (connect to pin 2 on sensor)
tylerjw 0:2bfb76da015b 76 */
tylerjw 0:2bfb76da015b 77 TMP36GZ(PinName pin);
tylerjw 0:2bfb76da015b 78
tylerjw 0:2bfb76da015b 79 /** Sample the sensor in deg C
tylerjw 0:2bfb76da015b 80 *
tylerjw 0:2bfb76da015b 81 * @returns float value in deg C
tylerjw 0:2bfb76da015b 82 */
tylerjw 0:2bfb76da015b 83 float sample();
tylerjw 0:2bfb76da015b 84
tylerjw 0:2bfb76da015b 85 /** Sample the sensor in deg F
tylerjw 0:2bfb76da015b 86 *
tylerjw 0:2bfb76da015b 87 * @returns float value in deg F
tylerjw 0:2bfb76da015b 88 */
tylerjw 0:2bfb76da015b 89 float sample_f();
tylerjw 0:2bfb76da015b 90 };