# in work !!!
from machine import TouchPad, Pin, PWM
import time
TOUCH_THRESHOLD = 300 # Adjust based on sensitivity testing
# Touch input pins (GPIO numbers)
touch_pins = [4, 15, 13, 12, 14, 27, 33, 32]
# Corresponding output pins for speaker mixing
pwm_pins = [25, 26, 27, 14, 32, 33, 16, 17]
# Frequencies for C major scale (C4 to C5)
frequencies = [262, 294, 330, 349, 392, 440, 494, 523]
# Set up touch sensors
touch_sensors = [TouchPad(Pin(pin)) for pin in touch_pins]
# Set up PWM outputs (initially off)
pwm_channels = [PWM(Pin(pin), freq=1000, duty=0) for pin in pwm_pins]
def play_note(index):
pwm_channels[index].freq(frequencies[index])
pwm_channels[index].duty(512) # 50% duty cycle
def stop_note(index):
pwm_channels[index].duty(0)
while True:
for i in range(8):
touch_value = touch_sensors[i].read()
if touch_value is not None and touch_value < TOUCH_THRESHOLD:
play_note(i)
else:
stop_note(i)
time.sleep_ms(20)