Created
March 22, 2016 05:05
-
-
Save compilerexe/ec4449a693d956847565 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "DHT.h" | |
| #include <Wire.h> | |
| #include <LiquidCrystal_I2C.h> | |
| #define DHTPIN 14 | |
| #define DHTTYPE DHT22 | |
| DHT dht(DHTPIN, DHTTYPE); | |
| LiquidCrystal_I2C lcd(0x27, 16, 2); | |
| /* ICON */ | |
| byte ICON_TEMP[8] {B00100,B01010,B01010,B01110,B01110,B11111,B11111,B01110}; | |
| byte ICON_HUMID[8] {B00100,B00100,B01010,B01010,B10001,B10001,B10001,B01110}; | |
| unsigned long previousMillis = 0; | |
| const long interval = 2000; | |
| void ledDisplay(float temp, float humid) { | |
| lcd.clear(); | |
| lcd.setCursor(0, 1); | |
| lcd.print(" "); | |
| lcd.write(1); | |
| lcd.print(" : "); | |
| lcd.print(temp); | |
| lcd.print(" C"); | |
| lcd.setCursor(0, 2); | |
| lcd.print(" "); | |
| lcd.write(2); | |
| lcd.print(" : "); | |
| if (humid <= 9) { | |
| lcd.print("0"); | |
| } | |
| lcd.print(humid); | |
| lcd.print(" %"); | |
| } | |
| void setup() { | |
| Serial.begin(115200); | |
| dht.begin(); | |
| lcd.begin(); | |
| lcd.createChar(1, ICON_TEMP); | |
| lcd.createChar(2, ICON_HUMID); | |
| } | |
| void loop() { | |
| unsigned long currentMillis = millis(); | |
| if (currentMillis - previousMillis >= interval) { | |
| previousMillis = currentMillis; | |
| float h = dht.readHumidity(); | |
| float t = dht.readTemperature(); | |
| if (isnan(h) || isnan(t)) { | |
| Serial.println("Failed to read from DHT sensor!"); | |
| return; | |
| } | |
| Serial.print("Temp : "); | |
| Serial.println(t); | |
| Serial.print("Humid : "); | |
| Serial.println(h); | |
| ledDisplay(t, h); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment