0
0
Raspberry Piprogramming~10 mins

Digital output (GPIO.output) 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 set GPIO pin 18 as output.

Raspberry Pi
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, [1])
Drag options to blanks, or click blank then click option'
AGPIO.PWM
BGPIO.IN
CGPIO.OUT
DGPIO.SPI
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.IN instead of GPIO.OUT
Confusing pin modes with communication protocols
2fill in blank
medium

Complete the code to turn GPIO pin 18 ON (set it HIGH).

Raspberry Pi
GPIO.output(18, [1])
Drag options to blanks, or click blank then click option'
AGPIO.TRUE
BGPIO.LOW
CGPIO.ON
DGPIO.HIGH
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.LOW to turn the pin ON
Using non-existent constants like GPIO.ON
3fill in blank
hard

Fix the error in the code to turn GPIO pin 23 OFF (set it LOW).

Raspberry Pi
GPIO.output(23, [1])
Drag options to blanks, or click blank then click option'
AGPIO.LOW
BGPIO.HIGH
CGPIO.TRUE
DGPIO.ON
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.HIGH to turn the pin OFF
Using invalid constants like GPIO.ON
4fill in blank
hard

Fill both blanks to create a dictionary of pin states for pins 17 and 27, setting 17 HIGH and 27 LOW.

Raspberry Pi
pin_states = {17: [1], 27: [2]
Drag options to blanks, or click blank then click option'
AGPIO.HIGH
BGPIO.LOW
CGPIO.OUT
DGPIO.IN
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.OUT or GPIO.IN as pin states
Mixing up HIGH and LOW values
5fill in blank
hard

Fill all three blanks to set up pin 22 as output, turn it ON, and then clean up GPIO.

Raspberry Pi
GPIO.setup(22, [1])
GPIO.output(22, [2])
GPIO.[3]()
Drag options to blanks, or click blank then click option'
AGPIO.IN
BGPIO.HIGH
Ccleanup
DGPIO.OUT
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.IN instead of GPIO.OUT for setup
Forgetting to call cleanup()
Using wrong constants for output