from machine import PWM, Pin
import time
pwm = PWM(Pin(21))
pwm1 = PWM(Pin(19))
pwm.freq(1000)
pwm1.freq(1000)
button_pin = Pin(15, Pin.IN, Pin.PULL_UP)
button_state = False
def run_while_loop():
while True:
for i in range(0, 65025, 100):
pwm.duty_u16(i)
print(pwm.duty_u16())
time.sleep_ms(10)
pwm.duty_u16(0)
for i in range(65025, 0, -100):
pwm1.duty_u16(i)
print(pwm1.duty_u16())
time.sleep_ms(10)
pwm1.duty_u16(0)
try:
while True:
while button_pin.value():
pass
run_while_loop()
except KeyboardInterrupt:
print("程序被用戶中斷")
finally:
pwm.duty_u16(0)
pwm1.duty_u16(0)