Created
July 25, 2021 15:37
-
-
Save EwhaWhiteMoon/9e1827d1d56293499518e1206e6613a0 to your computer and use it in GitHub Desktop.
갸아아악
This file contains 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
//LiquidCrystalI2C Library | |
#include <Wire.h> | |
#include <LiquidCrystal_I2C.h> | |
//DHT_Sensor Library | |
#include <Adafruit_Sensor.h> | |
#include <DHT.h> | |
//Servo Library | |
#include <Servo.h> | |
/*LCD 2개 SETUP (휴대폰, 실내) | |
거리 센서(시력보호용) | |
조도센서 (밝기가 일정 이하면 조명 Toggle) | |
지문센서 : 나중에 | |
온습도 센서(실내) | |
조명 설정용 버튼 2개 | |
온도 설정용 가변저항 | |
*/ | |
//#define LCD_SDA A4 | |
//#define LCD_SCL A5 | |
//I2C 통신은 한 회선으로 여러 기기 사용 가능 | |
#define LCD1_ADDR | |
#define LCD2_ADDR | |
//주소 찾아 쓰기 | |
#define S_CdS A0 // 조도센서 | |
#define S_TSET A1 // 온도 설정 | |
//#define S_FINGER_IN //지문센서IN | |
//#define S_FINGER_OUT //지문센서OUT | |
#define S_DIST 2 // 거리 센서 | |
#define S_DHT 3 // DHT11 온습도센서 | |
#define S_LBUT1 4 // 조명 설정 1 | |
#define S_LBUT2 5 // 조명 설정 2 | |
#define S_YMBUT 6 // 요리모드 버튼 | |
#define S_DUSTLED 7 // 미세먼지센서 LED | |
#define S_DUSTVO A2 // 미세먼지센서 Vo | |
#define Light1 8 // 조명1 | |
#define Light2 9 // 조명2 | |
#define AirCon 10 // 에어컨 | |
#define AirClean 11 // 공기청정기 | |
#define W_Servo 12 // 창문(pwm 되는 핀인지 확인하기) | |
LiquidCrystal_I2C lcdPhone(LCD1_ADDR, 16, 2); | |
LiquidCrystal_I2C lcdHome(LCD2_ADDR, 16, 2); | |
DHT dht(S_DHT, DHT11); | |
Servo window; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(S_DIST, INPUT); | |
pinMode(S_LBUT1, INPUT); | |
pinMode(S_LBUT2, INPUT); | |
pinMode(S_YMBUT, INPUT); | |
pinMode(S_CdS, INPUT); | |
pinMode(S_TSET, INPUT); | |
pinMode(S_DUSTLED, OUTPUT); | |
pinMode(S_DUSTVO, INPUT); | |
pinMode(Light1, OUTPUT); | |
pinMode(Light2, OUTPUT); | |
pinMode(AirCon, OUTPUT); | |
pinMode(AirClean, OUTPUT); | |
window.attach(W_Servo) | |
dht.begin(); // dht sensor start | |
lcd1.init(); // lcd1 start | |
lcd2.init(); // lcd2 start | |
lcd1.backlight(); // lcd1 backlight | |
lcd2.backlight(); // lcd2 backlight | |
} | |
int temp; //현재 온도 | |
int tempSet; //설정 온도 | |
int dust; //현재 미세먼지 센서 값 | |
bool YMode = false; //요리모드 설정값 | |
void toggleYM(){ | |
YMode = !YMode; | |
setW(YMode); | |
} | |
void setW(bool s){ | |
//TODO: 창문 열고닫기 구현; | |
} | |
bool light[2] //현재 조명 값 | |
void turnOnLight(bool l){ | |
light[l] = true; | |
lightImit(); | |
} | |
void turnOffLight(int l){ | |
light[l] = false; | |
lightImit(); | |
} | |
void toggleLight(int l){ | |
light[l] = !light[l]; | |
lightImit(); | |
} | |
void lightImit(){ | |
//TODO : 조명 변화 구현하기 | |
} | |
int getDust(){ | |
int dustValue; | |
digitalWrite(S_DUSTLED, LOW); | |
delayMicroseconds(280); | |
dustValue = analogRead(S_DUSTVO); | |
delayMicroseconds(40); | |
digitalWrite(S_DUSTLED, HIGH); | |
return dustValue; //TODO : 보정해주기! | |
} | |
void loop() { | |
//거리센서 읽어와서 LCD 백라이트 조절하기 | |
//버튼 읽어와서 조명 Toggle 하기 | |
//버튼 읽어와서 요리모드 Toggle 하기 | |
//센서값 읽어오기 부분 | |
/*온도, 습도 읽어오기 | |
*설정온도 읽어오기 | |
*미세먼지값 읽어오기 | |
* | |
*/ | |
/* ---------------------------------------- */ | |
//센서값 처리하기 부분 | |
/* 온도, 설정온도 비교해서 설정온도보다 온도가 높으면 에어컨 on, 낮으면 off | |
* (요리모드 아니면) 미세먼지값 확인해서 보통(수치 확인 필요) 보다 높으면 공기청정기 on, 낮으면 off | |
* (요리모드면) 무조건 공기청정기 on | |
* 바깥 밝기 확인해서 낮으면 조명 on | |
* | |
* 스마트폰 쪽 LCD 온습도,미세먼지 농도 | |
* 집 쪽 LCD 온습도, 미세먼지 농도 | |
*/ | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment