I’m trying to create something with my bread and pi but the button is saying that it is pressed and when ever it does say that it is off the LED light blinks off then back on. I’ve tried new buttons and I feel this is a software issue
This is my code
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()