Created
October 2, 2015 07:14
-
-
Save kaizenlabs/449943138dd3d957aeb2 to your computer and use it in GitHub Desktop.
Mini Project Example For Lecture 36: Arduino Step By Step on Udemy
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 <Keypad.h> | |
#include <LCD.h> | |
#include <LiquidCrystal_I2C.h> | |
#include <DHT.h> | |
#include <Wire.h> | |
#define DHTPIN 10 | |
#define DHTTYPE DHT22 | |
DHT dht(DHTPIN,DHTTYPE); | |
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE); | |
const byte ROWS = 4; | |
const byte COLS = 4; | |
char hexaKeys[ROWS][COLS]= { | |
{'1','2','3','A'}, | |
{'4','5','6','B'}, | |
{'7','8','9','C'}, | |
{'*','0','#','D'} | |
}; | |
byte rowPins [COLS] = {2,3,4,5}; | |
byte colPins [ROWS] = {6,7,8,9}; | |
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); | |
void setup() { | |
// put your setup code here, to run once: | |
lcd.begin(16,2); | |
lcd.backlight(); | |
lcd.setCursor(3,0); | |
lcd.print("Conditions:"); | |
} | |
void loop() { | |
float h = dht.readHumidity(); | |
float t = dht.readTemperature(); | |
char customKey = customKeypad.getKey(); | |
if (customKey == '1') { | |
if(isnan(h) || isnan(t)){ | |
lcd.clear(); | |
lcd.setCursor(3,0); | |
lcd.print("Conditions: "); | |
lcd.setCursor(3,1); | |
lcd.print("Cannot Read");} else { | |
lcd.setCursor(1,1); | |
lcd.print("Temp: "); | |
lcd.print(t*1.8+32); | |
lcd.print(" F"); | |
} | |
} | |
if (customKey == '2') { | |
if(isnan(h) || isnan(t)){ | |
lcd.clear(); | |
lcd.setCursor(3,0); | |
lcd.print("Conditions: "); | |
lcd.setCursor(3,1); | |
lcd.print("Cannot Read");} else{ | |
lcd.setCursor(1,1); | |
lcd.print("Hum.: "); | |
lcd.print(h); | |
lcd.print(" %"); | |
} | |
} | |
if (customKey == '3') { | |
lcd.clear(); | |
lcd.setCursor(3,0); | |
lcd.print("Conditions: "); | |
int sensorValue = analogRead(A0); | |
lcd.setCursor(4,1); | |
lcd.print("Light: "); | |
lcd.print(sensorValue); | |
} | |
if (customKey == '4'){ | |
lcd.clear(); | |
lcd.setCursor(3,0); | |
lcd.print("Conditions: "); | |
lcd.setCursor(5,1); | |
lcd.print("Hello!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment