arrow_forward
music_note
arrow_forward
music_note
def annoying_sound():
speaker.play(523, 0.1)
sleep(0.1)
speaker.play(523, 0.4)
def happy_sound():
for i in range(2000, 5000, 100):
speaker.play(i, 0.05)
annoying_button.when_pressed = annoying_sound
happy_button.when_pressed = happy_sound
lightbulb
.when_pressed
.when_pressed will call the function when the button is pressed.
arrow_forward
music_note
music_note
music_note
music_note
def tune():
my_tune = [ ['d5', 0.4], ['d#5', 0.4],
['f5', 0.4], ['d6', 0.4] ]
for note in my_tune:
pink_led.on()
speaker.play(note)
pink_led.off()
sleep(0.2)
play_tune.when_pressed = tune
bug_report
Don't use brackets ()
When you call the function e.g. tune, don't use brackets at the end.