Raspberry Pi - LED and Button Projects
Consider this code snippet:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
button_pressed = False
def button_callback(channel):
global button_pressed
button_pressed = True
GPIO.add_event_detect(18, GPIO.FALLING, callback=button_callback, bouncetime=200)
print("Waiting for button press...")
while not button_pressed:
time.sleep(0.1)
print("Button was pressed!")
GPIO.cleanup()What will be printed when the button connected to pin 18 is pressed?
