Fixed HalloWing_Jump_Sound example to work on M4 and M0
@@ -6,12 +6,11 @@ support). WILL work with earlier versions, just no image shown!
"""
import time
-import pulseio
import audioio
import busio
import board
+import digitalio
import touchio
-import adafruit_lis3dh
import neopixel
def load_wav(name):
@@ -39,8 +38,27 @@ JUMP_WAV = load_wav('jump') # WAV file to play when jumping
JUMP_THRESHOLD = 4.0 # Higher number = triggers more easily
IMAGEFILE = 'mario.bmp' # BMP image to display
+IS_HALLOWING_M4 = False
+
+# Perform a couple extra steps for the HalloWing M4
+try:
+ if getattr(board, "CAP_PIN"):
+ IS_HALLOWING_M4 = True
+ # Create digitalio objects and pull low for HalloWing M4
+ cap_pin = digitalio.DigitalInOut(board.CAP_PIN)
+ cap_pin.direction = digitalio.Direction.OUTPUT
+ cap_pin.value = False
+ if getattr(board, "SPEAKER_ENABLE"):
+ # Enable the Speaker
+ speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
+ speaker_enable.direction = digitalio.Direction.OUTPUT
+ speaker_enable.value = True
+except AttributeError:
+ pass
+
AUDIO = audioio.AudioOut(board.A0) # Speaker
-BACKLIGHT = pulseio.PWMOut(board.TFT_BACKLIGHT) # Display backlight
+
+board.DISPLAY.auto_brightness = False
TOUCH1 = touchio.TouchIn(board.A2) # Capacitive touch pads
TOUCH2 = touchio.TouchIn(board.A3)
TOUCH3 = touchio.TouchIn(board.A4)
@@ -48,6 +66,11 @@ TOUCH4 = touchio.TouchIn(board.A5)
# Set up accelerometer on I2C bus, 4G range:
I2C = busio.I2C(board.SCL, board.SDA)
+if IS_HALLOWING_M4:
+ import adafruit_msa301
+ ACCEL = adafruit_msa301.MSA301(I2C)
+else:
+ import adafruit_lis3dh
try:
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x18) # Production board
except ValueError:
@@ -56,15 +79,15 @@ ACCEL.range = adafruit_lis3dh.RANGE_4_G
try:
import displayio
+ board.DISPLAY.brightness = 0
SCREEN = displayio.Group()
board.DISPLAY.show(SCREEN)
BITMAP = displayio.OnDiskBitmap(open(IMAGEFILE, 'rb'))
SCREEN.append(
- displayio.Sprite(BITMAP,
+ displayio.TileGrid(BITMAP,
pixel_shader=displayio.ColorConverter(),
- position=(0, 0)))
- board.DISPLAY.wait_for_frame() # Wait for the image to load.
- BACKLIGHT.duty_cycle = 65535 # Turn on display backlight
+ x=0, y=0))
+ board.DISPLAY.brightness = 1.0
except (ImportError, NameError, AttributeError) as err:
pass # Probably earlier CircuitPython; no displayio support
