Skip to content

Commit 9fcaa63

Browse files
authored
Merge pull request #851 from makermelissa/master
Fixed HalloWing_Jump_Sound example to work on M4 and M0
2 parents b1c9995 + 6a35c66 commit 9fcaa63

1 file changed

Lines changed: 36 additions & 13 deletions

File tree

Hallowing_Jump_Sound/jump-sound.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
"""
77

88
import time
9-
import pulseio
109
import audioio
1110
import busio
1211
import board
12+
import digitalio
1313
import touchio
14-
import adafruit_lis3dh
1514
import neopixel
1615

1716
def load_wav(name):
@@ -39,32 +38,56 @@ def play_wav(wav):
3938
JUMP_THRESHOLD = 4.0 # Higher number = triggers more easily
4039
IMAGEFILE = 'mario.bmp' # BMP image to display
4140

41+
IS_HALLOWING_M4 = False
42+
43+
# Perform a couple extra steps for the HalloWing M4
44+
try:
45+
if getattr(board, "CAP_PIN"):
46+
IS_HALLOWING_M4 = True
47+
# Create digitalio objects and pull low for HalloWing M4
48+
cap_pin = digitalio.DigitalInOut(board.CAP_PIN)
49+
cap_pin.direction = digitalio.Direction.OUTPUT
50+
cap_pin.value = False
51+
if getattr(board, "SPEAKER_ENABLE"):
52+
# Enable the Speaker
53+
speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
54+
speaker_enable.direction = digitalio.Direction.OUTPUT
55+
speaker_enable.value = True
56+
except AttributeError:
57+
pass
58+
4259
AUDIO = audioio.AudioOut(board.A0) # Speaker
43-
BACKLIGHT = pulseio.PWMOut(board.TFT_BACKLIGHT) # Display backlight
60+
61+
board.DISPLAY.auto_brightness = False
4462
TOUCH1 = touchio.TouchIn(board.A2) # Capacitive touch pads
4563
TOUCH2 = touchio.TouchIn(board.A3)
4664
TOUCH3 = touchio.TouchIn(board.A4)
4765
TOUCH4 = touchio.TouchIn(board.A5)
4866

4967
# Set up accelerometer on I2C bus, 4G range:
5068
I2C = busio.I2C(board.SCL, board.SDA)
51-
try:
52-
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x18) # Production board
53-
except ValueError:
54-
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x19) # Beta hardware
55-
ACCEL.range = adafruit_lis3dh.RANGE_4_G
69+
if IS_HALLOWING_M4:
70+
import adafruit_msa301
71+
ACCEL = adafruit_msa301.MSA301(I2C)
72+
else:
73+
import adafruit_lis3dh
74+
try:
75+
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x18) # Production board
76+
except ValueError:
77+
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x19) # Beta hardware
78+
ACCEL.range = adafruit_lis3dh.RANGE_4_G
5679

5780
try:
5881
import displayio
82+
board.DISPLAY.brightness = 0
5983
SCREEN = displayio.Group()
6084
board.DISPLAY.show(SCREEN)
6185
BITMAP = displayio.OnDiskBitmap(open(IMAGEFILE, 'rb'))
6286
SCREEN.append(
63-
displayio.Sprite(BITMAP,
64-
pixel_shader=displayio.ColorConverter(),
65-
position=(0, 0)))
66-
board.DISPLAY.wait_for_frame() # Wait for the image to load.
67-
BACKLIGHT.duty_cycle = 65535 # Turn on display backlight
87+
displayio.TileGrid(BITMAP,
88+
pixel_shader=displayio.ColorConverter(),
89+
x=0, y=0))
90+
board.DISPLAY.brightness = 1.0
6891
except (ImportError, NameError, AttributeError) as err:
6992
pass # Probably earlier CircuitPython; no displayio support
7093

0 commit comments

Comments
 (0)