0

我正在尝试用我的面包和 pi 创建一些东西,但是按钮说它已被按下,并且当它确实说它关闭时,LED 灯会闪烁然后再亮。我尝试了新按钮,我觉得这是一个软件问题

这是我的代码

import drivers
import time

display = drivers.Lcd()

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM);

GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)

GPIO.setup(13, GPIO.OUT)
GPIO.output(13, 0)

fanOn = False
display.lcd_display_string("Fan: off", 1)   # Write line of text to first line of display


try:
    while True:
        GPIO.output(13, GPIO.input(19))

        if GPIO.input(13) == 0 & fanOn == True:
            GPIO.output(13, 0)
            display.lcd_backlight(1) #turns on backlight
            display.lcd_clear()
            display.lcd_display_string("Fan: off", 1)   # Write line of text to first line of display
            print("off")
            fanOn = False
            time.sleep(0.5)
        elif GPIO.input(13) == 0 & fanOn == False:
            GPIO.output(13, 1)
            display.lcd_backlight(1) #turns on backlight
            display.lcd_clear()
            display.lcd_display_string("Fan: on ", 1)   # Write line of text to first line of display
            print("on")
            fanOn = True
            time.sleep(0.5)
        else:
            continue
except KeyboardInterrupt:
    GPIO.cleanup()
    display.lcd_clear()
4

0 回答 0