5
5
import gc
6
6
import board
7
7
import busio
8
+ import audioio
8
9
import audiocore
9
10
import displayio
10
11
import digitalio
11
- from adafruit_pyportal import PyPortal
12
12
from adafruit_bitmap_font import bitmap_font
13
13
from adafruit_display_text import bitmap_label as label
14
14
from adafruit_display_shapes .circle import Circle
15
15
from adafruit_button import Button
16
16
import adafruit_touchscreen
17
17
from adafruit_mcp9600 import MCP9600
18
18
19
- pyportal = PyPortal ()
20
-
21
19
TITLE = "EZ Make Oven Controller"
22
- VERSION = "1.3.0 "
20
+ VERSION = "1.3.1 "
23
21
24
22
print (TITLE , "version " , VERSION )
25
23
time .sleep (2 )
@@ -91,11 +89,21 @@ def __init__(self):
91
89
)
92
90
self .sine_wave_sample = audiocore .RawSample (sine_wave )
93
91
92
+ self ._speaker_enable = digitalio .DigitalInOut (board .SPEAKER_ENABLE )
93
+ self ._speaker_enable .switch_to_output (False )
94
+
95
+ if hasattr (board , "AUDIO_OUT" ):
96
+ self .audio = audioio .AudioOut (board .AUDIO_OUT )
97
+ elif hasattr (board , "SPEAKER" ):
98
+ self .audio = audioio .AudioOut (board .SPEAKER )
99
+ else :
100
+ raise AttributeError ("Board does not have a builtin speaker!" )
101
+
94
102
# pylint: disable=protected-access
95
103
def play (self , duration = 0.1 ):
96
- if not pyportal . peripherals ._speaker_enable .value :
97
- pyportal . peripherals ._speaker_enable .value = True
98
- pyportal . peripherals .audio .play (self .sine_wave_sample , loop = True )
104
+ if not self ._speaker_enable .value :
105
+ self ._speaker_enable .value = True
106
+ self .audio .play (self .sine_wave_sample , loop = True )
99
107
self .start = time .monotonic ()
100
108
self .duration = duration
101
109
if duration <= 0.5 :
@@ -105,10 +113,10 @@ def play(self, duration=0.1):
105
113
self .stop ()
106
114
107
115
def stop (self ):
108
- if pyportal . peripherals ._speaker_enable .value :
116
+ if self ._speaker_enable .value :
109
117
self .duration = 0
110
- pyportal . peripherals .audio .stop ()
111
- pyportal . peripherals ._speaker_enable .value = False
118
+ self .audio .stop ()
119
+ self ._speaker_enable .value = False
112
120
113
121
def refresh (self ):
114
122
if time .monotonic () - self .start >= self .duration :
0 commit comments