20
20
display .auto_refresh = False
21
21
22
22
i2c = board .I2C ()
23
- dac = adafruit_tlv320 .TLV320DAC3100 (i2c )
23
+ # Check if DAC is connected
24
+ while not i2c .try_lock ():
25
+ time .sleep (0.01 )
26
+ if 0x18 in i2c .scan ():
27
+ ltv320_present = True
28
+ else :
29
+ ltv320_present = False
30
+ i2c .unlock ()
24
31
25
- # set sample rate & bit depth
26
- dac . configure_clocks ( sample_rate = 11030 , bit_depth = 16 )
32
+ if ltv320_present :
33
+ dac = adafruit_tlv320 . TLV320DAC3100 ( i2c )
27
34
28
- # use headphones
29
- dac .headphone_output = True
30
- dac .headphone_volume = - 15 # dB
35
+ # set sample rate & bit depth
36
+ dac .configure_clocks (sample_rate = 11030 , bit_depth = 16 )
31
37
32
- wave_file = open ("/boot_animation/ada_fruitjam_boot_jingle.wav" , "rb" )
33
- wave = WaveFile (wave_file )
34
- audio = audiobusio .I2SOut (board .I2S_BCLK , board .I2S_WS , board .I2S_DIN )
38
+ # use headphones
39
+ dac .headphone_output = True
40
+ dac .headphone_volume = - 15 # dB
41
+
42
+ wave_file = open ("/boot_animation/ada_fruitjam_boot_jingle.wav" , "rb" )
43
+ wave = WaveFile (wave_file )
44
+ audio = audiobusio .I2SOut (board .I2S_BCLK , board .I2S_WS , board .I2S_DIN )
35
45
36
46
37
47
class OvershootAnimator :
@@ -621,7 +631,8 @@ def cancel(self):
621
631
622
632
start_time = time .monotonic ()
623
633
624
- audio .play (wave )
634
+ if ltv320_present :
635
+ audio .play (wave )
625
636
626
637
while True :
627
638
now = time .monotonic ()
@@ -668,8 +679,9 @@ def cancel(self):
668
679
if not still_going :
669
680
break
670
681
671
- while audio .playing :
672
- pass
682
+ if ltv320_present :
683
+ while audio .playing :
684
+ pass
673
685
674
686
supervisor .set_next_code_file ("code.py" )
675
687
supervisor .reload ()
0 commit comments