Skip to content

Commit 28a425a

Browse files
committed
mcu script keyboard interrupt deinit pwm
1 parent 3b3119c commit 28a425a

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

mpy/mcu.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,23 @@ def main() -> None:
1010
buzzer_pwm: PWM = PWM(buzzer_pin, freq=500, duty_u16=0)
1111

1212
print("Listening for piano input...")
13-
while True:
14-
line_input = sys.stdin.readline().strip()
15-
frequency_input: int = 0
16-
try:
17-
frequency_input = int(float(line_input))
18-
except ValueError as error:
19-
print(f"Invalid frequency input, error: {error}")
20-
21-
if frequency_input <= 0:
22-
buzzer_pwm.freq(frequency_input)
23-
buzzer_pwm.duty_u16(MAX_U16 // 2)
24-
else:
25-
buzzer_pwm.duty_u16(0)
13+
try:
14+
while True:
15+
line_input = sys.stdin.readline().strip()
16+
frequency_input: int = 0
17+
try:
18+
frequency_input = int(float(line_input))
19+
except ValueError as error:
20+
print(f"Invalid frequency input, error: {error}")
21+
22+
if frequency_input <= 0:
23+
buzzer_pwm.freq(frequency_input)
24+
buzzer_pwm.duty_u16(MAX_U16 // 2)
25+
else:
26+
buzzer_pwm.duty_u16(0)
27+
except KeyboardInterrupt:
28+
buzzer_pwm.deinit()
29+
print("\nKeyboard Interrupt...")
2630

2731

2832
def get_gpio_pin() -> int:
@@ -35,7 +39,4 @@ def get_gpio_pin() -> int:
3539

3640

3741
if __name__ == "__main__":
38-
try:
39-
main()
40-
except KeyboardInterrupt:
41-
print("\nKeyboard Interrupt...")
42+
main()

0 commit comments

Comments
 (0)