-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudioalert.py
More file actions
32 lines (28 loc) · 883 Bytes
/
audioalert.py
File metadata and controls
32 lines (28 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from machine import Pin
from utime import sleep
class CAudioAlert:
def __init__(self):
self.alertDelay = 2.5
self.speaker = Pin(15, Pin.OUT)
self.tonesOn = True
def use_audio(self, flag):
self.tonesOn = (flag == "Yes")
print("Audio status : ", self.tonesOn)
def beeps(self, threeBeeps=True):
if self.tonesOn:
if threeBeeps:
print("audio working")
self.speaker.value(1)
sleep(0.15)
self.speaker.value(0)
sleep(0.85)
self.speaker.value(1)
sleep(0.15)
self.speaker.value(0)
sleep(0.85)
self.speaker.value(1)
sleep(0.15)
self.speaker.value(0)
else:
print("audio not working")
self.alertDelay = 2.15