0
0
Raspberry Piprogramming~10 mins

LED toggle with button in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the GPIO library.

Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
ARPi.GPIO
Bgpiozero
Ctime
Dsys
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated libraries like 'time' or 'sys' instead of GPIO library.
2fill in blank
medium

Complete the code to set the GPIO mode to BCM numbering.

Raspberry Pi
GPIO.setmode([1])
Drag options to blanks, or click blank then click option'
AGPIO.BOARD
BGPIO.BCM
CGPIO.IN
DGPIO.OUT
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.BOARD instead of GPIO.BCM for BCM numbering.
3fill in blank
hard

Fix the error in setting up the button pin as input with pull-up resistor.

Raspberry Pi
GPIO.setup(18, [1], pull_up_down=GPIO.PUD_UP)
Drag options to blanks, or click blank then click option'
AGPIO.OUT
BGPIO.PUD_DOWN
CGPIO.IN
DGPIO.PUD_UP
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the pin as output instead of input.
4fill in blank
hard

Fill both blanks to toggle the LED state when the button is pressed.

Raspberry Pi
if GPIO.input(18) == [1]:
    led_state = not [2]
Drag options to blanks, or click blank then click option'
AGPIO.LOW
BGPIO.HIGH
Cled_state
Dbutton_state
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for GPIO.HIGH instead of GPIO.LOW for button press.
Toggling wrong variable.
5fill in blank
hard

Fill all three blanks to set up the LED pin, initialize its state, and update it.

Raspberry Pi
GPIO.setup([1], GPIO.OUT)
led_state = [2]
GPIO.output([3], led_state)
Drag options to blanks, or click blank then click option'
A17
BFalse
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong pin number.
Starting LED state as True instead of False.