Why is it important to call GPIO.cleanup() at the end of a Raspberry Pi program controlling multiple LEDs?
hard📝 Conceptual Q10 of 15
Raspberry Pi - LED and Button Projects
Why is it important to call GPIO.cleanup() at the end of a Raspberry Pi program controlling multiple LEDs?
AIt automatically saves the LED pattern to a file.
BIt resets all GPIO pins to a safe state to prevent unexpected behavior.
CIt speeds up the program execution.
DIt increases the brightness of the LEDs.
Step-by-Step Solution
Solution:
Step 1: Understand GPIO.cleanup() purpose
GPIO.cleanup() resets all GPIO pins used by the program to inputs, preventing them from staying on or causing issues after the program ends.
Step 2: Analyze options
Only It resets all GPIO pins to a safe state to prevent unexpected behavior. correctly describes this safety feature. Other options are unrelated to cleanup().
Final Answer:
It resets all GPIO pins to a safe state to prevent unexpected behavior. -> Option B
Quick Check:
cleanup() resets pins safely = It resets all GPIO pins to a safe state to prevent unexpected behavior. [OK]
Quick Trick:Always call GPIO.cleanup() to reset pins safely [OK]
Common Mistakes:
Thinking cleanup affects LED brightness
Assuming cleanup speeds execution
Believing cleanup saves patterns
Master "LED and Button Projects" in Raspberry Pi
9 interactive learning modes - each teaches the same concept differently