simple temperature sensor

Dependents:   HARP2 HARP3 Thermostat_NucleoF401 4180Lab4_p1 ... more

Committer:
tylerjw
Date:
Thu Sep 20 23:12:45 2012 +0000
Revision:
0:2bfb76da015b
Child:
4:24ce620f145c
0.1 tested and working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tylerjw 0:2bfb76da015b 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 * C++ 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 "TMP36GZ.h"
tylerjw 0:2bfb76da015b 43
tylerjw 0:2bfb76da015b 44 TMP36GZ::TMP36GZ(PinName pin)
tylerjw 0:2bfb76da015b 45 {
tylerjw 0:2bfb76da015b 46 input_pin_ = new AnalogIn(pin);
tylerjw 0:2bfb76da015b 47 }
tylerjw 0:2bfb76da015b 48
tylerjw 0:2bfb76da015b 49 float TMP36GZ::sample()
tylerjw 0:2bfb76da015b 50 {
tylerjw 0:2bfb76da015b 51 return input_pin_->read() * 330.0 - 50.0;
tylerjw 0:2bfb76da015b 52 }
tylerjw 0:2bfb76da015b 53
tylerjw 0:2bfb76da015b 54 float TMP36GZ::sample_f()
tylerjw 0:2bfb76da015b 55 {
tylerjw 0:2bfb76da015b 56 return sample() * 1.8 + 32.0;
tylerjw 0:2bfb76da015b 57 }