Tyler Weaver / TMP36 GZ

Dependents:   HARP2 HARP3 Thermostat_NucleoF401 4180Lab4_p1 ... more

Committer:
tylerjw
Date:
Thu Sep 20 23:24:28 2012 +0000
Revision:
4:24ce620f145c
Parent:
0:2bfb76da015b
Child:
8:2b0feb7bdebc
0.5

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 4:24ce620f145c 28 * /----\
tylerjw 4:24ce620f145c 29 * |1 2 3 |
tylerjw 4:24ce620f145c 30 * --------
tylerjw 0:2bfb76da015b 31 *
tylerjw 0:2bfb76da015b 32 * 1 - Vs, connect 3.3V (Vout)
tylerjw 0:2bfb76da015b 33 * 2 - Vout - connect to input pin
tylerjw 0:2bfb76da015b 34 * 3 - GND - connect to ground
tylerjw 0:2bfb76da015b 35 *
tylerjw 4:24ce620f145c 36 * 750mV = 25 deg/C
tylerjw 0:2bfb76da015b 37 *
tylerjw 0:2bfb76da015b 38 * 10mV / deg/C
tylerjw 0:2bfb76da015b 39 */
tylerjw 0:2bfb76da015b 40 #include "TMP36GZ.h"
tylerjw 0:2bfb76da015b 41
tylerjw 0:2bfb76da015b 42 TMP36GZ::TMP36GZ(PinName pin)
tylerjw 0:2bfb76da015b 43 {
tylerjw 0:2bfb76da015b 44 input_pin_ = new AnalogIn(pin);
tylerjw 0:2bfb76da015b 45 }
tylerjw 0:2bfb76da015b 46
tylerjw 0:2bfb76da015b 47 float TMP36GZ::sample()
tylerjw 0:2bfb76da015b 48 {
tylerjw 0:2bfb76da015b 49 return input_pin_->read() * 330.0 - 50.0;
tylerjw 0:2bfb76da015b 50 }
tylerjw 0:2bfb76da015b 51
tylerjw 0:2bfb76da015b 52 float TMP36GZ::sample_f()
tylerjw 0:2bfb76da015b 53 {
tylerjw 0:2bfb76da015b 54 return sample() * 1.8 + 32.0;
tylerjw 0:2bfb76da015b 55 }