Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the gpiozero library.
Raspberry Pi
from gpiozero import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GPIO' which is not a class in gpiozero
Using 'Pin' or 'Board' which are not classes to control LEDs
✗ Incorrect
The LED class is part of gpiozero and is used to control an LED easily.
2fill in blank
mediumComplete the code to create an LED object on GPIO pin 17.
Raspberry Pi
led = LED([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing pin numbers not matching the example
Confusing physical pin numbers with GPIO numbers
✗ Incorrect
GPIO pin 17 is commonly used and matches the example to control the LED.
3fill in blank
hardFix the error in the code to turn the LED on.
Raspberry Pi
led.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'off' which turns the LED off
Using 'start' or 'enable' which are not gpiozero methods
✗ Incorrect
The on() method turns the LED on in gpiozero.
4fill in blank
hardFill both blanks to create a Button on pin 2 and check if it is pressed.
Raspberry Pi
button = Button([1]) if button.[2]: print('Pressed!')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pin 3 instead of 2
Using 'pressed' which is not a gpiozero property
✗ Incorrect
The Button class uses pin 2 here, and is_pressed is the property to check if the button is pressed.
5fill in blank
hardFill all three blanks to create a PWMLED on pin 18, set brightness to 50%, and turn it on.
Raspberry Pi
pwm_led = PWMLED([1]) pwm_led.[2] = [3] pwm_led.on()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pin 17 instead of 18
Setting brightness to 1 instead of 0.5
✗ Incorrect
Pin 18 is used for PWMLED, brightness controls the light level, and 0.5 sets it to 50% brightness.