我是python的新手,编码困难。我目前正在使用覆盆子pi,dht传感器进行学校项目,并且无法在按下的按钮内循环播放脚本。我正在使用5个按钮,并希望它发挥作用,如果我按下其中一个按钮,它将循环一些代码,直到按下另一个按钮为止。
我已经尝试编码,但是在按下一个按钮后,它只会读取一次,但希望它继续读取脚本而无需再次按下按钮
尝试: DHT22Sensor = Adafruit_DHT.DHT22
hum, temp = Adafruit_DHT.read_retry(DHT22Sensor, 4)
while(1):
if GPIO.input(B1)==0:
print('Threshold is 32.5-33.5')
#control the fan based on the temp
if BS1==False:
if(temp > TEMP_THRESHOLD):
GPIO.output(FAN_PIN, True)
if(temp > ALERT_THRESHOLD):
os.system('/home/pi/Poultry/pushbullet.sh "Alert Fan May Not Functioning"')
if(temp < (TEMP_HYST)):
GPIO.output(FAN_PIN, False)
if(temp < ALERT_HYST):
os.system('/home/pi/Poultry/pushbullet.sh "Alert Out of Chicken Comfort Zone"')
BS1=True
time.sleep(.1)
else:
BS1=False
time.sleep(.1)
GPIO.wait_for_edge(B1, GPIO.FALLING)
elif GPIO.input(B2)==0:
print('Threshold is 30.5-31.5')
#control the fan based on the temp
if BS2==False:
if(temp > (TEMP_THRESHOLD-2)):
GPIO.output(FAN_PIN, True)
if(temp > (ALERT_THRESHOLD-2)):
os.system('/home/pi/Poultry/pushbullet.sh "Alert Fan May Not Functioning"')
if(temp < (TEMP_HYST-2)):
GPIO.output(FAN_PIN, False)
if(temp < (ALERT_HYST-2)):
os.system('/home/pi/Poultry/pushbullet.sh "Alert Out of Chicken Comfort Zone"')
BS2=True
time.sleep(.1)
else:
BS2=False
time.sleep(.1)
最后: GPIO.cleanup()