pi_pico_lab/piano.py

26 lines
756 B
Python
Raw Normal View History

2022-04-08 11:30:22 +00:00
from time import sleep
from telemetrix_rpi_pico import telemetrix_rpi_pico
2022-04-08 18:10:39 +00:00
from siwatlib.debounce import debounce
from siwatlib.sound import beep
2022-04-08 11:30:22 +00:00
import winsound
index_shift = 2
2022-04-08 18:10:39 +00:00
freqs = [261.6256,293.6648,329.6276,349.2282,391.9954,440.0000,493.8833,523.2511]
debouncers = []
2022-04-08 11:30:22 +00:00
def handle_button_press(data):
2022-04-08 18:10:39 +00:00
freq = freqs[data[1]-index_shift]
2022-04-08 11:30:22 +00:00
print(freq)
2022-04-08 18:10:39 +00:00
recieved_state = not data[2]
if debouncers[data[1]-index_shift].set_state(state=recieved_state):
beep(frequency=freq,duration=0.25)
2022-04-08 11:30:22 +00:00
mcu = telemetrix_rpi_pico.TelemetrixRpiPico(com_port='COM10')
2022-04-08 18:10:39 +00:00
2022-04-08 11:30:22 +00:00
for i in range(2,10):
2022-04-08 18:10:39 +00:00
debouncers.append(debounce(state=False,debounce_time=0.15))
2022-04-08 11:30:22 +00:00
mcu.set_pin_mode_digital_input(i,callback=handle_button_press)
while True:
sleep(100)