Skip to content

Commit 46c41bf

Browse files
committed
Check for unsupported frequencies in Buzzer
1 parent 007693d commit 46c41bf

File tree

1 file changed

+5
-36
lines changed

1 file changed

+5
-36
lines changed

src/modulino/buzzer.py

+5-36
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,6 @@ class ModulinoBuzzer(Modulino):
88
"""
99

1010
NOTES: dict[str, int] = {
11-
"B0": 31,
12-
"C1": 33,
13-
"CS1": 35,
14-
"D1": 37,
15-
"DS1": 39,
16-
"E1": 41,
17-
"F1": 44,
18-
"FS1": 46,
19-
"G1": 49,
20-
"GS1": 52,
21-
"A1": 55,
22-
"AS1": 58,
23-
"B1": 62,
24-
"C2": 65,
25-
"CS2": 69,
26-
"D2": 73,
27-
"DS2": 78,
28-
"E2": 82,
29-
"F2": 87,
30-
"FS2": 93,
31-
"G2": 98,
32-
"GS2": 104,
33-
"A2": 110,
34-
"AS2": 117,
35-
"B2": 123,
36-
"C3": 131,
37-
"CS3": 139,
38-
"D3": 147,
39-
"DS3": 156,
40-
"E3": 165,
41-
"F3": 175,
4211
"FS3": 185,
4312
"G3": 196,
4413
"GS3": 208,
@@ -102,10 +71,7 @@ class ModulinoBuzzer(Modulino):
10271
"""
10372
Dictionary with the notes and their corresponding frequencies.
10473
The supported notes are defined as follows:
105-
- B0
106-
- C1, CS1, D1, DS1, E1, F1, FS1, G1, GS1, A1, AS1, B1
107-
- C2, CS2, D2, DS2, E2, F2, FS2, G2, GS2, A2, AS2, B2
108-
- C3, CS3, D3, DS3, E3, F3, FS3, G3, GS3, A3, AS3, B3
74+
- FS3, G3, GS3, A3, AS3, B3
10975
- C4, CS4, D4, DS4, E4, F4, FS4, G4, GS4, A4, AS4, B4
11076
- C5, CS5, D5, DS5, E5, F5, FS5, G5, GS5, A5, AS5, B5
11177
- C6, CS6, D6, DS6, E6, F6, FS6, G6, GS6, A6, AS6, B6
@@ -134,10 +100,13 @@ def tone(self, frequency: int, lenght_ms: int = 0xFFFF, blocking: bool = False)
134100
If blocking is set to True, the function will wait until the tone is finished.
135101
136102
Parameters:
137-
frequency: The frequency of the tone in Hz
103+
frequency: The frequency of the tone in Hz (freuqencies below 180 Hz are not supported)
138104
lenght_ms: The duration of the tone in milliseconds. If omitted, the tone will play indefinitely
139105
blocking: If set to True, the function will wait until the tone is finished
140106
"""
107+
if frequency < 180 and frequency != 0:
108+
raise ValueError("Frequency must be greater than 180 Hz")
109+
141110
self.data[0:4] = frequency.to_bytes(4, 'little')
142111
self.data[4:8] = lenght_ms.to_bytes(4, 'little')
143112
self.write(self.data)

0 commit comments

Comments
 (0)