My code is this below:
Code: Select all
import RPi.GPIO as gpio
gpio.setwarnings(False)
gpio.setmode(gpio.BCM)
gpio.setup(18, gpio.OUT)
gpio.setup(22, gpio.IN)
while True:
if gpio.input(22) == 0:
gpio.output(18, gpio.LOW)
print('low')
else:
gpio.output(18, gpio.HIGH)
print('high')
The problem is when I release the button: the light doesn't turn off but only decreases the brightness and the values oscillate between 'low' and 'high' continuously.
Did I write something wrong?