Play a single note
# play middle c for 1 second
speaker.play('c4')
lightbulb Note names
Notes go from 'c1' (low) to 'd8' (high) and include sharps 'f#5'.
bug_report My note doesn't play
-
Make sure you are using a value between
'c1'and'd8'. -
Make sure you have imported the
Speaker. -
Make sure you have set the pin number for the
Speaker.
Play multiple notes
# Ta-Daaa!
speaker.play('c4', 0.1) # short c note
sleep(0.1) # rest
speaker.play('c4', 0.4) # long c note
lightbulb Note length
The default length is 1 second. Specify a different length with a number.
lightbulb Use a rest
A rest is a short break in the tune. If you don't add in a rest then the notes can blend into one.