Bird
0
0

Given this code snippet, what is the error?

medium📝 Debug Q14 of 15
Raspberry Pi - PWM Output
Given this code snippet, what is the error?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18, 50)
pwm.start(7.5)
# Missing cleanup
AGPIO pins are not cleaned up after use
BPWM frequency is incorrect
CDuty cycle value is out of range
DGPIO mode is not set
Step-by-Step Solution
Solution:
  1. Step 1: Review code for setup and cleanup

    The code sets mode, pin, and starts PWM correctly but does not call GPIO.cleanup().
  2. Step 2: Identify missing cleanup importance

    Not cleaning up GPIO pins can cause warnings or errors on next runs.
  3. Final Answer:

    GPIO pins are not cleaned up after use -> Option A
  4. Quick Check:

    Missing GPIO.cleanup() = A [OK]
Quick Trick: Always call GPIO.cleanup() after PWM use [OK]
Common Mistakes:
  • Ignoring GPIO.cleanup()
  • Thinking frequency or duty cycle is wrong here
  • Forgetting to set GPIO mode

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes