Skip to content

Commit a9123da

Browse files
authored
Merge pull request #1495 from lesamouraipourpre/master
Remove the dependency on PyPortal in the PyPortal_EZ_Make_Oven learn …
2 parents 4251724 + e3da6b6 commit a9123da

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

PyPortal_EZ_Make_Oven/code.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@
55
import gc
66
import board
77
import busio
8+
import audioio
89
import audiocore
910
import displayio
1011
import digitalio
11-
from adafruit_pyportal import PyPortal
1212
from adafruit_bitmap_font import bitmap_font
1313
from adafruit_display_text import bitmap_label as label
1414
from adafruit_display_shapes.circle import Circle
1515
from adafruit_button import Button
1616
import adafruit_touchscreen
1717
from adafruit_mcp9600 import MCP9600
1818

19-
pyportal = PyPortal()
20-
2119
TITLE = "EZ Make Oven Controller"
22-
VERSION = "1.3.0"
20+
VERSION = "1.3.1"
2321

2422
print(TITLE, "version ", VERSION)
2523
time.sleep(2)
@@ -91,11 +89,21 @@ def __init__(self):
9189
)
9290
self.sine_wave_sample = audiocore.RawSample(sine_wave)
9391

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+
94102
# pylint: disable=protected-access
95103
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)
99107
self.start = time.monotonic()
100108
self.duration = duration
101109
if duration <= 0.5:
@@ -105,10 +113,10 @@ def play(self, duration=0.1):
105113
self.stop()
106114

107115
def stop(self):
108-
if pyportal.peripherals._speaker_enable.value:
116+
if self._speaker_enable.value:
109117
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
112120

113121
def refresh(self):
114122
if time.monotonic() - self.start >= self.duration:

0 commit comments

Comments
 (0)