0
0
Raspberry Piprogramming~10 mins

Buzzer and TonalBuzzer 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 create a Buzzer on GPIO pin 17.

Raspberry Pi
from gpiozero import Buzzer
buzzer = Buzzer([1])
Drag options to blanks, or click blank then click option'
A17
B18
C27
D22
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong GPIO pin number.
Passing the pin number as a string instead of an integer.
2fill in blank
medium

Complete the code to turn the buzzer on.

Raspberry Pi
from gpiozero import Buzzer
buzzer = Buzzer(17)
buzzer.[1]()
Drag options to blanks, or click blank then click option'
Aoff
Bon
Ctoggle
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using off() instead of on().
Using toggle() which switches state but does not guarantee on.
3fill in blank
hard

Fix the error in the code to play a tone of 440 Hz for 1 second using TonalBuzzer.

Raspberry Pi
from gpiozero import TonalBuzzer, Tone
import time
buzzer = TonalBuzzer(17)
buzzer.play([1])
time.sleep(1)
buzzer.stop()
Drag options to blanks, or click blank then click option'
ATone(frequency=440)
BTone(440)
C440
D440Hz
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an integer directly instead of a Tone object.
Using a string like '440Hz' which is invalid.
4fill in blank
hard

Fill both blanks to create a TonalBuzzer on pin 18 and play a 523 Hz tone.

Raspberry Pi
from gpiozero import TonalBuzzer, Tone
buzzer = TonalBuzzer([1])
tone = Tone([2])
buzzer.play(tone)
Drag options to blanks, or click blank then click option'
A18
B17
C523
D440
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up pin numbers and frequencies.
Passing frequency to TonalBuzzer instead of Tone.
5fill in blank
hard

Fill all three blanks to create a dictionary of tones with their frequencies and play the 659 Hz tone.

Raspberry Pi
from gpiozero import TonalBuzzer, Tone
buzzer = TonalBuzzer([1])
tones = {'E': Tone([2]), 'G': Tone(784)}
buzzer.play(tones[[3]])
Drag options to blanks, or click blank then click option'
A17
B659
C'E'
D'G'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pin number.
Using the wrong frequency for the 'E' tone.
Not using quotes around the dictionary key.