from machine import Pin, PWM
from utime import sleep
# lower right corner with USB connector on top
SPEAKER_PIN = 7
# create a Pulse Width Modulation Object on this pin
speaker = PWM(Pin(SPEAKER_PIN))
# https://docs.arduino.cc/built-in-examples/digital/toneMelody/
NOTE_B5 = 988
NOTE_E6 = 1319
# the time each tone will be on
ON_TIME = .09
# the time between the tones
OFF_TIME = .001
# https://bikeshedeffect.weebly.com/arduino-piezo-sounds.html
speaker.duty_u16(100)
speaker.freq(NOTE_B5)
sleep(ON_TIME)
speaker.duty_u16(0)
sleep(OFF_TIME)
speaker.duty_u16(850)
speaker.freq(NOTE_E6)
# sleep(ON_TIME)
sleep(0.4)
speaker.duty_u16(0)
sleep(OFF_TIME)
# how do I get that reverb on the last note? https://www.youtube.com/watch?v=iFubmEcqtC4
# lol https://www.reddit.com/r/WeAreTheMusicMakers/comments/7m6tv6/super_mario_coin_sound_composition/
# Also... the Mario coin sound is B6, E7 with the E7 duration a tad longer.. https://www.electro-tech-online.com/threads/8-bit-mario-coin-sound-effect-on-pic.117231/page-2#post-1187410
# turn off the PWM
speaker.duty_u16(0)