Raspberry Pi,A2302传感器,5v风扇
QN 如何请求连接到GPIO 18的风扇激活并保持活动状态,直到我的传感器在引脚5的温度读数低于26摄氏度或湿度为不到60%?
#!/usr/bin/python
import time
import Adafruit_DHT
import RPi.GPIO as GPIO
sensor = Adafruit_DHT.AM2302
pin = 5
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
else:
print('Failed to get reading. Try again!')
GPIO.setmode(GPIO.BCM)
GPIO.setup(18,GPIO.OUT)
GPIO.output(18, 1)
time.sleep(5)
GPIO.output(18, 0)
GPIO.cleanup()
答案 0 :(得分:0)
我无法提供实际代码,但您似乎只想知道要使用的逻辑?
do the following once every minute (or however often):
if temp< 26
turn off fan
elseif hum < 60
turn off fan
else
keep fan on