Почему мой Raspberry Pi говорит, что кнопка нажата

Я пытаюсь создать что-то с моим хлебом и пи, но кнопка говорит, что она нажата, и когда она говорит, что она выключена, светодиодный индикатор мигает, а затем снова включается. Я пробовал новые кнопки и считаю, что это проблема программного обеспечения

Это мой код

      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()

0 ответов

Другие вопросы по тегам