Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the GPIO library.
Raspberry Pi
import [1] as GPIO
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'gpiozero' instead of 'RPi.GPIO' when using low-level GPIO control.
Importing unrelated libraries like 'os' or 'flask'.
✗ Incorrect
The RPi.GPIO library is used to control GPIO pins on Raspberry Pi.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.BOARD when BCM numbering is required.
Confusing pin modes with numbering modes.
✗ Incorrect
Using GPIO.BCM sets the pin numbering to Broadcom SOC channel numbers.
3fill in blank
hardFix the error in setting up pin 18 as output.
Raspberry Pi
GPIO.setup(18, [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.IN instead of GPIO.OUT for output pins.
Using invalid constants like GPIO.PWM or GPIO.INPUT.
✗ Incorrect
To control an LED or output device, the pin must be set as GPIO.OUT.
4fill in blank
hardFill both blanks to create a Flask route that turns the LED on.
Raspberry Pi
from flask import Flask, [1] app = Flask(__name__) @app.route('/led/on') def led_on(): GPIO.output(18, [2]) return 'LED is ON'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.LOW to turn LED on (it turns it off).
Not importing 'request' when needed in Flask.
✗ Incorrect
The Flask request module is commonly imported for routes, and GPIO.HIGH turns the LED on.
5fill in blank
hardFill all three blanks to complete the Flask app that controls the LED state based on URL parameter.
Raspberry Pi
from flask import Flask, request app = Flask(__name__) @app.route('/led/<state>') def led_control(state): if state == '[1]': GPIO.output(18, [2]) else: GPIO.output(18, [3]) return f'LED turned {state}'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'on' and 'off' strings in the condition.
Using GPIO.LOW to turn LED on.
✗ Incorrect
The URL parameter state is checked for 'on' to set the pin HIGH; otherwise, it sets LOW to turn off the LED.