11"""
22Jump & touch sound example for Adafruit Hallowing. Plays different sounds
33in response to jumping and capacitive touch pads.
4- Image display requires CircuitPython 4.0.0-alpha1 or later (with displayio
5- support). WILL work with earlier versions, just no image shown!
64"""
75
86import time
9- import busio
107import board
118import digitalio
9+ import displayio
1210import audioio
1311import audiocore
1412import touchio
@@ -57,16 +55,16 @@ def play_wav(wav):
5755except AttributeError :
5856 pass
5957
60- AUDIO = audioio .AudioOut (board .A0 ) # Speaker
58+ AUDIO = audioio .AudioOut (board .SPEAKER ) # Speaker
6159
6260board .DISPLAY .auto_brightness = False
63- TOUCH1 = touchio .TouchIn (board .A2 ) # Capacitive touch pads
64- TOUCH2 = touchio .TouchIn (board .A3 )
65- TOUCH3 = touchio .TouchIn (board .A4 )
66- TOUCH4 = touchio .TouchIn (board .A5 )
61+ TOUCH1 = touchio .TouchIn (board .TOUCH1 ) # Capacitive touch pads
62+ TOUCH2 = touchio .TouchIn (board .TOUCH2 )
63+ TOUCH3 = touchio .TouchIn (board .TOUCH3 )
64+ TOUCH4 = touchio .TouchIn (board .TOUCH4 )
6765
6866# Set up accelerometer on I2C bus, 4G range:
69- I2C = busio .I2C (board . SCL , board . SDA )
67+ I2C = board .I2C ()
7068if IS_HALLOWING_M4 :
7169 import adafruit_msa301
7270 ACCEL = adafruit_msa301 .MSA301 (I2C )
@@ -79,18 +77,25 @@ def play_wav(wav):
7977 ACCEL .range = adafruit_lis3dh .RANGE_4_G
8078
8179try :
82- import displayio
8380 board .DISPLAY .brightness = 0
8481 SCREEN = displayio .Group ()
8582 board .DISPLAY .show (SCREEN )
83+
84+ # CircuitPython 6 & 7 compatible
8685 BITMAP = displayio .OnDiskBitmap (open (IMAGEFILE , 'rb' ))
87- SCREEN .append (
88- displayio .TileGrid (BITMAP ,
89- pixel_shader = getattr (BITMAP , 'pixel_shader' , displayio .ColorConverter ()),
90- x = 0 , y = 0 ))
91- board .DISPLAY .brightness = 1.0
92- except (ImportError , NameError , AttributeError ) as err :
93- pass # Probably earlier CircuitPython; no displayio support
86+ TILEGRID = displayio .TileGrid (
87+ BITMAP ,
88+ pixel_shader = getattr (BITMAP , 'pixel_shader' , displayio .ColorConverter ())
89+ )
90+
91+ # # CircuitPython 7+ compatible
92+ # BITMAP = displayio.OnDiskBitmap(IMAGEFILE)
93+ # TILEGRID = displayio.TileGrid(BITMAP, pixel_shader=BITMAP.pixel_shader)
94+
95+ SCREEN .append (TILEGRID )
96+ board .DISPLAY .brightness = 1.0 # Turn on display backlight
97+ except (OSError , ValueError ):
98+ pass
9499
95100# If everything has initialized correctly, turn off the onboard NeoPixel:
96101PIXEL = neopixel .NeoPixel (board .NEOPIXEL , 1 , brightness = 0 )
0 commit comments