from machine import Pin, PWM
from utime import sleep_ms
import _thread
from neopixel import NeoPixel
np = NeoPixel(Pin(23), 16)
buzzer = PWM (Pin(14))
for i in range(16):
np[i]=255,0,0
np.write()
note = {
'a': 392, 'a#': 415, 'b': 440, 'f': 622, 'f#': 659, 'g': 698,
'c': 466, 'C#': 494, 'd': 523, 'd#': 554, 'e': 587, 'g#': 740 }
NOTES=('a', 'a#', 'b', 'c', 'C#', 'd', 'd#','f', 'f#', 'g', 'g#')
buz_pin=14
def freq(note):
if len(note) ==3:
octave=int(note[2])
else:
octave=int(note[1])
key_no=NOTES.index(note[:-1])
if key_no<3:
key_no=key_no+12+((octave-1)*12)+1
else:
key_no=key_no+((octave-1)*12)+1
return 440* (2**((kry_no-49)/12))
def tone (pin, freq, time):
buzzer=PWM(Pin(pin), freq=freq, duty=512)
sleep_ms(time)
buzzer.deinit()