Complete the code to import the GPIO library for Raspberry Pi.
import [1] as GPIO
The RPi.GPIO library is used to control GPIO pins on Raspberry Pi.
Complete the code to set the GPIO mode to BCM numbering.
GPIO.setmode([1])Setting GPIO mode to GPIO.BCM uses the Broadcom chip pin numbers.
Fix the error in setting up a GPIO pin 17 as input with a pull-up resistor.
GPIO.setup(17, [1], pull_up_down=GPIO.PUD_UP)
Pin 17 should be set as input (GPIO.IN) to use a pull-up resistor.
Fill both blanks to add an event detection on pin 18 for falling edge and assign a callback function.
GPIO.add_event_detect(18, [1], callback=[2])
The event detection is set for falling edge (GPIO.FALLING) and the callback function is button_pressed.
Fill all three blanks to define a Button class with an __init__ method that sets pin, callback, and configures GPIO input with pull-up.
class Button: def __init__(self, pin, callback): self.pin = [1] self.callback = [2] GPIO.setup(self.pin, GPIO.IN, pull_up_down=[3])
The __init__ method assigns the pin and callback parameters to instance variables and sets up the pin as input with pull-up resistor.