Raspberry Pi - LED and Button Projects
What is wrong with this code snippet that tries to detect a button press on GPIO pin 22?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN)
def on_press(channel):
print("Button pressed")
GPIO.add_event_detect(22, GPIO.RISING, callback=on_press)
while True:
pass
GPIO.cleanup()