import dht
from machine import Pin
import time
from utime import sleep
button_pin = Pin(4, Pin.IN, Pin.PULL_DOWN) #각 요소 별 핀 설정
led_red = Pin(9, Pin.OUT)
led_blue = Pin(12, Pin.OUT)
sensor = dht.DHT22(Pin(18))
#온습도 기준 값 리스트로 저장
th_input = open("input.txt", "r")
tem_input = th_input.readline().strip("\n")
hum_input = th_input.readline().strip("\n")
tm_st = tem_input.split()
hm_st = hum_input.split()
r = 0
cu_tm_st = int(tm_st[r])
cu_hm_st = int(hm_st[r])
t = 0
h = 0
while True:
#현 온습도 측정
sleep(3)
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
#버튼 누를 때마다 기준값 변경
if button_pin.value() == 1:
if r <= 4:
r+= 1
cu_hm_st = int(tm_st[r])
cu_hm_st = int(hm_st[r])
elif r == 5:
r = 0
cu_hm_st = int(tm_st[r])
cu_hm_st = int(hm_st[r])
#온습도 기준값 이상 달성시 t,h 값 조정
if temp >= cu_tm_st:
t += 1
elif temp < cu_tm_st:
t = 0
if hum >= cu_hm_st:
h += 1
elif hum < cu_hm_st:
h = 0
while t <= 2:
time.sleep(1.5)
led_red.value(1)
time.sleep(1.5)
led_red.value(0)
else:
time.sleep(1)
led_red.value(1)
time.sleep(1)
led_red.value(0)
while h <= 2:
time.sleep(1.5)
led_blue.value(1)
time.sleep(1.5)
led_blue.value(0)
else:
time.sleep(1)
led_blue.value(1)
time.sleep(1)
led_blue.value(0)