0
0
Raspberry Piprogramming~10 mins

Why PWM is needed for analog-like control in Raspberry Pi - Test Your Understanding

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

Complete the code to start PWM on pin 18 with a frequency of 1000 Hz.

Raspberry Pi
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18, [1])
pwm.start(0)
Drag options to blanks, or click blank then click option'
A50
B500
C1000
D2000
Attempts:
3 left
💡 Hint
Common Mistakes
Using too low or too high frequency causing flickering or no effect.
2fill in blank
medium

Complete the code to set the duty cycle to 75%, which controls the analog-like output level.

Raspberry Pi
pwm.ChangeDutyCycle([1])
Drag options to blanks, or click blank then click option'
A25
B75
C50
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing duty cycle with frequency or using values outside 0-100.
3fill in blank
hard

Fix the error in the code to properly stop PWM and clean up GPIO.

Raspberry Pi
pwm.[1]()
GPIO.cleanup()
Drag options to blanks, or click blank then click option'
Astop
Bclose
Cend
Dterminate
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like close() or end() causing runtime errors.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each brightness level to its duty cycle if the level is greater than 50.

Raspberry Pi
brightness_levels = [30, 60, 90]
duty_cycles = {level: [1] for level in brightness_levels if level [2] 50}
Drag options to blanks, or click blank then click option'
Alevel
B>
C<
Dlevel * 2
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or incorrect value expressions.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps the uppercase level name to its duty cycle if the duty cycle is less than 80.

Raspberry Pi
levels = {'low': 30, 'medium': 60, 'high': 90}
filtered = { [1]: [2] for [3] in levels.items() if [2] < 80 }
Drag options to blanks, or click blank then click option'
Alevel.upper()
Bduty
Clevel, duty
Dlevels
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or forgetting to unpack items.