Complete the code to import the GPIO library.
import [1]
We use RPi.GPIO to control GPIO pins on Raspberry Pi.
Complete the code to set the GPIO mode to BCM numbering.
GPIO.setmode([1])BCM mode uses the Broadcom chip pin numbers.
Fix the error in setting up pin 17 as input with pull-up resistor.
GPIO.setup(17, [1], pull_up_down=GPIO.PUD_UP)
Pin 17 must be set as input to detect button presses.
Fill both blanks to read the button state and print if pressed.
button_state = GPIO.input([1]) if button_state == [2]: print('Button pressed!')
We read pin 17 and check if it is LOW because the button pulls the pin to ground when pressed.
Fill all three blanks to set up a button press event detection with a callback.
def button_callback(channel): print('Button was pressed!') GPIO.setup([1], GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect([2], GPIO.FALLING, callback=[3], bouncetime=200)
Pin 17 is set up as input with pull-up. Event detection triggers on falling edge (button press) and calls button_callback.
