Skip audio output if DAC not attached
This commit is contained in:
parent
d7302ea2a7
commit
235ed6018b
1 changed files with 24 additions and 12 deletions
|
|
@ -20,6 +20,16 @@ display = supervisor.runtime.display
|
|||
display.auto_refresh = False
|
||||
|
||||
i2c = board.I2C()
|
||||
# Check if DAC is connected
|
||||
while not i2c.try_lock():
|
||||
time.sleep(0.01)
|
||||
if 0x18 in i2c.scan():
|
||||
ltv320_present = True
|
||||
else:
|
||||
ltv320_present = False
|
||||
i2c.unlock()
|
||||
|
||||
if ltv320_present:
|
||||
dac = adafruit_tlv320.TLV320DAC3100(i2c)
|
||||
|
||||
# set sample rate & bit depth
|
||||
|
|
@ -621,6 +631,7 @@ display.root_group = main_group
|
|||
|
||||
start_time = time.monotonic()
|
||||
|
||||
if ltv320_present:
|
||||
audio.play(wave)
|
||||
|
||||
while True:
|
||||
|
|
@ -668,6 +679,7 @@ while True:
|
|||
if not still_going:
|
||||
break
|
||||
|
||||
if ltv320_present:
|
||||
while audio.playing:
|
||||
pass
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue