Tyler Weaver / TMP36 GZ

Dependents:   HARP2 HARP3 Thermostat_NucleoF401 4180Lab4_p1 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TMP36GZ.h Source File

TMP36GZ.h

00001 /*
00002 * Copyright (c) 2012 Tyler Weaver, MIT License
00003 *
00004 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00005 * and associated documentation files (the "Software"), to deal in the Software without restriction,
00006 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00007 
00008 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00009 * furnished to do so, subject to the following conditions:
00010 *
00011 * The above copyright notice and this permission notice shall be included in all copies or
00012 * substantial portions of the Software.
00013 *
00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00015 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00016 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00017 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00018 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00019 */
00020 
00021 #include "mbed.h"
00022 
00023 /** TMP36GZ temperature sensor class
00024 *
00025 * @author Tyler Weaver
00026 *
00027 * Example:
00028 * @code
00029 * #include "mbed.h"
00030 * #include "TMP36GZ.h"
00031 *
00032 * TMP36GZ temp_sensor(p20);
00033 * Serial pc(USBTX, USBRX); // tx, rx
00034 *
00035 * int main() {
00036 *     pc.baud(9600);
00037 *     while(1) {
00038 *         pc.printf("Temp: %6.3f deg/C - %6.3f deg/F\n", temp_sensor.sample(), temp_sensor.sample_f());
00039 *         wait(1.0); // wait 1 second
00040 *     }
00041 * }
00042 * @endcode
00043 *
00044 * @section DESCRIPTION
00045 *
00046 * C++ file for TMP36GZ temperature sensor library
00047 *
00048 *  /----\
00049 * |1 2 3 |
00050 * --------
00051 *
00052 * 1 - Vs, connect 3.3V (Vout)
00053 * 2 - Vout - connect to input pin
00054 * 3 - GND - connect to ground
00055 *
00056 * 750mV = 25 deg/C
00057 *
00058 * 10mV / deg/C
00059 */
00060 
00061 class TMP36GZ
00062 {
00063 public:
00064     /** Constructor for TMP36GZ sensor
00065     *
00066     * Analog input pin from p15-p20
00067     *
00068     * @param pin the analog input pin (connect to pin 2 on sensor)
00069     */
00070     TMP36GZ(PinName pin);
00071 
00072     /** Sample the sensor in deg C
00073     *
00074     * @returns float value in deg C
00075     */
00076     float sample();
00077 
00078     /** Sample the sensor in deg F
00079     *
00080     * @returns float value in deg F
00081     */
00082     float sample_f();
00083 
00084 private:
00085     AnalogIn *input_pin_;
00086 };