Skip to content

Commit 929c9eb

Browse files
authored
Merge pull request #1761 from lesamouraipourpre/hallowing-jump-sound
HalloWing Jump Sound: Update for CP7
2 parents 1e64c04 + 689a324 commit 929c9eb

2 files changed

Lines changed: 40 additions & 31 deletions

File tree

Hallowing_Jump_Sound/jump-sound.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
"""
22
Jump & touch sound example for Adafruit Hallowing. Plays different sounds
33
in 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

86
import time
9-
import busio
107
import board
118
import digitalio
9+
import displayio
1210
import audioio
1311
import audiocore
1412
import touchio
@@ -57,16 +55,16 @@ def play_wav(wav):
5755
except AttributeError:
5856
pass
5957

60-
AUDIO = audioio.AudioOut(board.A0) # Speaker
58+
AUDIO = audioio.AudioOut(board.SPEAKER) # Speaker
6159

6260
board.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()
7068
if 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

8179
try:
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:
96101
PIXEL = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0)

Hallowing_Jump_Sound/stomp-and-roar.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
detection based on "Full-Featured Pedometer Design Realized with 3-Axis
55
Digital Accelerometer" by Neil Zhao, Analog Dialogue Technical Journal,
66
June 2010.
7-
Image display requires CircuitPython 4.0.0-alpha1 or later (with displayio
8-
support). WILL work with earlier versions, just no image shown!
97
"""
108

119
import time
1210
import math
1311
import digitalio
12+
import displayio
1413
import board
15-
import busio
1614
import audioio
1715
import audiocore
1816
import neopixel
@@ -44,12 +42,12 @@ def load_wav(name):
4442
except AttributeError:
4543
pass
4644

47-
AUDIO = audioio.AudioOut(board.A0) # Speaker
45+
AUDIO = audioio.AudioOut(board.SPEAKER) # Speaker
4846

4947
board.DISPLAY.auto_brightness = False
5048

5149
# Set up accelerometer on I2C bus, 4G range:
52-
I2C = busio.I2C(board.SCL, board.SDA)
50+
I2C = board.I2C()
5351
if IS_HALLOWING_M4:
5452
import adafruit_msa301
5553
ACCEL = adafruit_msa301.MSA301(I2C)
@@ -73,21 +71,27 @@ def load_wav(name):
7371
FILTER_SUM = 0 # Initial average value
7472
FILTER_INDEX = 0 # Current position in sample-averaging buffer
7573

76-
# Display BMP image. If this fails, it's not catastrophic (probably just
77-
# older CircuitPython) and the code will continue with the step detection.
74+
# Display BMP image.
7875
try:
79-
import displayio
8076
board.DISPLAY.brightness = 0
8177
SCREEN = displayio.Group()
8278
board.DISPLAY.show(SCREEN)
79+
80+
# CircuitPython 6 & 7 compatible
8381
BITMAP = displayio.OnDiskBitmap(open(IMAGEFILE, 'rb'))
84-
SCREEN.append(
85-
displayio.TileGrid(BITMAP,
86-
pixel_shader=getattr(BITMAP, 'pixel_shader', displayio.ColorConverter()),
87-
x=0, y=0))
82+
TILEGRID = displayio.TileGrid(
83+
BITMAP,
84+
pixel_shader=getattr(BITMAP, 'pixel_shader', displayio.ColorConverter())
85+
)
86+
87+
# # CircuitPython 7+ compatible
88+
# BITMAP = displayio.OnDiskBitmap(IMAGEFILE)
89+
# TILEGRID = displayio.TileGrid(BITMAP, pixel_shader=BITMAP.pixel_shader)
90+
91+
SCREEN.append(TILEGRID)
8892
board.DISPLAY.brightness = 1.0 # Turn on display backlight
89-
except (ImportError, NameError, AttributeError) as err:
90-
pass # Probably earlier CircuitPython; no displayio support
93+
except (OSError, ValueError):
94+
pass
9195

9296
# If everything has initialized correctly, turn off the onboard NeoPixel:
9397
PIXEL = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0)

0 commit comments

Comments
 (0)