Augur rain MASTER

Dependencies:   mbed

Fork of 1A_PROJECT_DIGITAL by Jakkapan Keawsalak

Committer:
gamezajad
Date:
Tue Dec 08 19:25:47 2015 +0000
Revision:
0:ede9cc7e508b
1A

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gamezajad 0:ede9cc7e508b 1 /* mbed DHT22 Library
gamezajad 0:ede9cc7e508b 2 * Copyright (c) 2011, sford, http://mbed.org
gamezajad 0:ede9cc7e508b 3 *
gamezajad 0:ede9cc7e508b 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
gamezajad 0:ede9cc7e508b 5 * of this software and associated documnetation files (the "Software"), to deal
gamezajad 0:ede9cc7e508b 6 * in the Software without restriction, including without limitation the rights
gamezajad 0:ede9cc7e508b 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
gamezajad 0:ede9cc7e508b 8 * copies of the Software, and to permit persons to whom the Software is
gamezajad 0:ede9cc7e508b 9 * furished to do so, subject to the following conditions:
gamezajad 0:ede9cc7e508b 10 *
gamezajad 0:ede9cc7e508b 11 * The above copyright notice and this permission notice shall be included in
gamezajad 0:ede9cc7e508b 12 * all copies or substantial portions of the Software.
gamezajad 0:ede9cc7e508b 13 *
gamezajad 0:ede9cc7e508b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
gamezajad 0:ede9cc7e508b 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
gamezajad 0:ede9cc7e508b 16 * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
gamezajad 0:ede9cc7e508b 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
gamezajad 0:ede9cc7e508b 18 * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
gamezajad 0:ede9cc7e508b 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
gamezajad 0:ede9cc7e508b 20 * THE SOFTWARE.
gamezajad 0:ede9cc7e508b 21 */
gamezajad 0:ede9cc7e508b 22
gamezajad 0:ede9cc7e508b 23 #ifndef MBED_DHT22_H
gamezajad 0:ede9cc7e508b 24 #define MBED_DHT22_H
gamezajad 0:ede9cc7e508b 25
gamezajad 0:ede9cc7e508b 26 #include "mbed.h"
gamezajad 0:ede9cc7e508b 27
gamezajad 0:ede9cc7e508b 28 /**
gamezajad 0:ede9cc7e508b 29 * Currently supports DHT22 (SparkFun Electronics)
gamezajad 0:ede9cc7e508b 30 * Humidity and Temperature Sensor
gamezajad 0:ede9cc7e508b 31 *
gamezajad 0:ede9cc7e508b 32 * Features:
gamezajad 0:ede9cc7e508b 33 * > 3.3-6V Input
gamezajad 0:ede9cc7e508b 34 * > 1-1.5mA measuring current
gamezajad 0:ede9cc7e508b 35 * > 40-50uA standby current
gamezajad 0:ede9cc7e508b 36 * > Humidity from 0-100% RH
gamezajad 0:ede9cc7e508b 37 * > -40 - 80 degrees C temperature range
gamezajad 0:ede9cc7e508b 38 * > +-2% RH accuracy
gamezajad 0:ede9cc7e508b 39 * > +-0.5 degrees C
gamezajad 0:ede9cc7e508b 40 *
gamezajad 0:ede9cc7e508b 41 * Usages
gamezajad 0:ede9cc7e508b 42 * #include "DHT22.h"
gamezajad 0:ede9cc7e508b 43 *
gamezajad 0:ede9cc7e508b 44 * DTH22 dth22(PinName sda, PinName scl, int addr); // pin
gamezajad 0:ede9cc7e508b 45 *
gamezajad 0:ede9cc7e508b 46 * int main() {
gamezajad 0:ede9cc7e508b 47 * err=dth22.readData();
gamezajad 0:ede9cc7e508b 48 * if (err==0) {
gamezajad 0:ede9cc7e508b 49 printf("Temperature is %f.2 C\n",dht22.getTemperature());
gamezajad 0:ede9cc7e508b 50 printf("Humidity is %f.2 \%\n",dht22.getHumidity());
gamezajad 0:ede9cc7e508b 51 }
gamezajad 0:ede9cc7e508b 52 *
gamezajad 0:ede9cc7e508b 53 *
gamezajad 0:ede9cc7e508b 54 */
gamezajad 0:ede9cc7e508b 55
gamezajad 0:ede9cc7e508b 56 #define DHT22_ERROR_VALUE -99.5
gamezajad 0:ede9cc7e508b 57
gamezajad 0:ede9cc7e508b 58 typedef enum {
gamezajad 0:ede9cc7e508b 59 DHT_ERROR_NONE = 0,
gamezajad 0:ede9cc7e508b 60 DHT_BUS_HUNG,
gamezajad 0:ede9cc7e508b 61 DHT_ERROR_NOT_PRESENT,
gamezajad 0:ede9cc7e508b 62 DHT_ERROR_ACK_TOO_LONG,
gamezajad 0:ede9cc7e508b 63 DHT_ERROR_SYNC_TIMEOUT,
gamezajad 0:ede9cc7e508b 64 DHT_ERROR_DATA_TIMEOUT,
gamezajad 0:ede9cc7e508b 65 DHT_ERROR_CHECKSUM,
gamezajad 0:ede9cc7e508b 66 DHT_ERROR_TOO_QUICK
gamezajad 0:ede9cc7e508b 67 } DHT22_ERROR;
gamezajad 0:ede9cc7e508b 68
gamezajad 0:ede9cc7e508b 69 class DHT22 {
gamezajad 0:ede9cc7e508b 70 private:
gamezajad 0:ede9cc7e508b 71 time_t _lastReadTime;
gamezajad 0:ede9cc7e508b 72 PinName _data;
gamezajad 0:ede9cc7e508b 73 float _lastHumidity;
gamezajad 0:ede9cc7e508b 74 float _lastTemperature;
gamezajad 0:ede9cc7e508b 75 public:
gamezajad 0:ede9cc7e508b 76 DHT22(PinName Data);
gamezajad 0:ede9cc7e508b 77 ~DHT22();
gamezajad 0:ede9cc7e508b 78 DHT22_ERROR readData(void);
gamezajad 0:ede9cc7e508b 79 float getHumidity();
gamezajad 0:ede9cc7e508b 80 float getTemperatureC();
gamezajad 0:ede9cc7e508b 81 void clockReset();
gamezajad 0:ede9cc7e508b 82 };
gamezajad 0:ede9cc7e508b 83
gamezajad 0:ede9cc7e508b 84 #endif /*_DHT22_H_*/