0
0
Raspberry Piprogramming~10 mins

Controlling GPIO through web interface 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 import the GPIO library.

Raspberry Pi
import [1] as GPIO
Drag options to blanks, or click blank then click option'
Agpiozero
Bos
CRPi.GPIO
Dflask
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'.
2fill in blank
medium

Complete 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'
AGPIO.BCM
BGPIO.BOARD
CGPIO.OUT
DGPIO.IN
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.BOARD when BCM numbering is required.
Confusing pin modes with numbering modes.
3fill in blank
hard

Fix 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'
AGPIO.OUT
BGPIO.IN
CGPIO.PWM
DGPIO.INPUT
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.
4fill in blank
hard

Fill 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'
Arequest
BGPIO.HIGH
CGPIO.LOW
Drender_template
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.LOW to turn LED on (it turns it off).
Not importing 'request' when needed in Flask.
5fill in blank
hard

Fill 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'
Aon
BGPIO.HIGH
CGPIO.LOW
Doff
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'on' and 'off' strings in the condition.
Using GPIO.LOW to turn LED on.