Example program for the SHT1x sensor driver

Dependencies:   mbed

Committer:
NegativeBlack
Date:
Fri Nov 19 16:51:29 2010 +0000
Revision:
0:f850dfb07e93

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NegativeBlack 0:f850dfb07e93 1 /**
NegativeBlack 0:f850dfb07e93 2 * Copyright (c) 2010 Roy van Dam <roy@negative-black.org>
NegativeBlack 0:f850dfb07e93 3 * All rights reserved.
NegativeBlack 0:f850dfb07e93 4 *
NegativeBlack 0:f850dfb07e93 5 * Redistribution and use in source and binary forms, with or without
NegativeBlack 0:f850dfb07e93 6 * modification, are permitted provided that the following conditions
NegativeBlack 0:f850dfb07e93 7 * are met:
NegativeBlack 0:f850dfb07e93 8 * 1. Redistributions of source code must retain the above copyright
NegativeBlack 0:f850dfb07e93 9 * notice, this list of conditions and the following disclaimer.
NegativeBlack 0:f850dfb07e93 10 * 2. Redistributions in binary form must reproduce the above copyright
NegativeBlack 0:f850dfb07e93 11 * notice, this list of conditions and the following disclaimer in the
NegativeBlack 0:f850dfb07e93 12 * documentation and/or other materials provided with the distribution.
NegativeBlack 0:f850dfb07e93 13 *
NegativeBlack 0:f850dfb07e93 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
NegativeBlack 0:f850dfb07e93 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
NegativeBlack 0:f850dfb07e93 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
NegativeBlack 0:f850dfb07e93 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
NegativeBlack 0:f850dfb07e93 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
NegativeBlack 0:f850dfb07e93 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
NegativeBlack 0:f850dfb07e93 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
NegativeBlack 0:f850dfb07e93 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
NegativeBlack 0:f850dfb07e93 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
NegativeBlack 0:f850dfb07e93 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
NegativeBlack 0:f850dfb07e93 24 * SUCH DAMAGE.
NegativeBlack 0:f850dfb07e93 25 */
NegativeBlack 0:f850dfb07e93 26
NegativeBlack 0:f850dfb07e93 27 #include "mbed.h"
NegativeBlack 0:f850dfb07e93 28 #include "SHTx/sht15.hpp"
NegativeBlack 0:f850dfb07e93 29
NegativeBlack 0:f850dfb07e93 30 Serial pc(USBTX, USBRX);
NegativeBlack 0:f850dfb07e93 31 DigitalOut busy(LED1);
NegativeBlack 0:f850dfb07e93 32
NegativeBlack 0:f850dfb07e93 33 // I used p9 and p10 here but you
NegativeBlack 0:f850dfb07e93 34 // can use any other GPIO as well.
NegativeBlack 0:f850dfb07e93 35 SHTx::SHT15 sensor(p9, p10);
NegativeBlack 0:f850dfb07e93 36
NegativeBlack 0:f850dfb07e93 37 int
NegativeBlack 0:f850dfb07e93 38 main() {
NegativeBlack 0:f850dfb07e93 39 // Speed things up a bit.
NegativeBlack 0:f850dfb07e93 40 sensor.setOTPReload(false);
NegativeBlack 0:f850dfb07e93 41 sensor.setResolution(true);
NegativeBlack 0:f850dfb07e93 42
NegativeBlack 0:f850dfb07e93 43 while(1) {
NegativeBlack 0:f850dfb07e93 44 busy = true;
NegativeBlack 0:f850dfb07e93 45 sensor.update();
NegativeBlack 0:f850dfb07e93 46 busy = false;
NegativeBlack 0:f850dfb07e93 47
NegativeBlack 0:f850dfb07e93 48 // Temperature in celcius
NegativeBlack 0:f850dfb07e93 49 sensor.setScale(false);
NegativeBlack 0:f850dfb07e93 50 pc.printf("Temperature [ %3.2f C ]\r\n", sensor.getTemperature());
NegativeBlack 0:f850dfb07e93 51
NegativeBlack 0:f850dfb07e93 52 // Temperature in fahrenheit
NegativeBlack 0:f850dfb07e93 53 sensor.setScale(true);
NegativeBlack 0:f850dfb07e93 54 pc.printf(" [ %3.2f F ]\r\n", sensor.getTemperature());
NegativeBlack 0:f850dfb07e93 55
NegativeBlack 0:f850dfb07e93 56 // Relative Humidity
NegativeBlack 0:f850dfb07e93 57 pc.printf("Humdity [ %3.2f %% ]\r\n\n", sensor.getHumidity());
NegativeBlack 0:f850dfb07e93 58
NegativeBlack 0:f850dfb07e93 59 wait(5);
NegativeBlack 0:f850dfb07e93 60 }
NegativeBlack 0:f850dfb07e93 61 }