12
12
"""
13
13
14
14
from modulino import ModulinoBuzzer
15
+ from time import sleep
15
16
16
17
buzzer = ModulinoBuzzer ()
17
18
18
19
# Super Mario Bros theme intro
19
20
melody = [
20
21
(ModulinoBuzzer .NOTES ["E5" ], 125 ),
22
+ (ModulinoBuzzer .NOTES ["REST" ], 25 ),
21
23
(ModulinoBuzzer .NOTES ["E5" ], 125 ),
22
24
(ModulinoBuzzer .NOTES ["REST" ], 125 ),
23
25
(ModulinoBuzzer .NOTES ["E5" ], 125 ),
31
33
]
32
34
33
35
for note , duration in melody :
36
+ buzzer .tone (note , duration , blocking = True )
37
+
38
+ # Wait 2 seconds before playing the next melody
39
+ sleep (2 )
40
+
41
+ # Police siren sound effect
42
+ def generate_siren (frequency_start , frequency_end , total_duration , steps , iterations ):
43
+ siren = []
44
+ mid_point = steps // 2
45
+ duration_rise = total_duration // 2
46
+ duration_fall = total_duration // 2
47
+
48
+ for _ in range (iterations ):
49
+ for i in range (steps ):
50
+ if i < mid_point :
51
+ # Easing in rising part
52
+ step_duration = duration_rise // mid_point + (duration_rise // mid_point * (mid_point - i ) // mid_point )
53
+ frequency = int (frequency_start + (frequency_end - frequency_start ) * (i / mid_point ))
54
+ else :
55
+ # Easing in falling part
56
+ step_duration = duration_fall // mid_point + (duration_fall // mid_point * (i - mid_point ) // mid_point )
57
+ frequency = int (frequency_end - (frequency_end - frequency_start ) * ((i - mid_point ) / mid_point ))
58
+
59
+ siren .append ((frequency , step_duration ))
60
+
61
+ return siren
62
+
63
+ # 4 seconds up and down siren, with 200 steps and 2 iterations
64
+ siren_melody = generate_siren (440 , 880 , 4000 , 200 , 2 )
65
+
66
+ for note , duration in siren_melody :
34
67
buzzer .tone (note , duration , blocking = True )
0 commit comments