from machine import Pin, PWM, ADC
import time
# 부저와 LED 초기화
buzzer = PWM(Pin(13))
led = PWM(Pin(18))
led.freq(1000)
pot = ADC(Pin(26))
notes = (262, 294, 330, 349, 392, 440, 494, 523)
while True:
for f in notes:
buzzer.freq(f)
# 포텐셔미터 값 읽기
raw = pot.read_u16() # 0~65535
# ON 시간 비율 계산 (0.1 ~ 0.9)
on_ratio = 0.1 + (raw / 65535) * 0.8
duration = 0.5 # 음 하나당 전체 시간
on_time = duration * on_ratio
off_time = duration - on_time
# 부저 ON/OFF
buzzer.duty_u16(32768) # 최대 출력
led.duty_u16(int(raw / 2)) # LED 밝기
time.sleep(on_time)
buzzer.duty_u16(0)
led.duty_u16(0)
time.sleep(off_time)