1010
1111import time
1212import math
13+ import digitalio
1314import board
1415import busio
1516import audioio
16- import pulseio
1717import neopixel
18- import adafruit_lis3dh
1918
2019def load_wav (name ):
2120 """
@@ -30,16 +29,36 @@ def load_wav(name):
3029ROAR_WAV = load_wav ('roar' ) # WAV when jumping
3130IMAGEFILE = 'reptar.bmp' # BMP image to display
3231
32+ IS_HALLOWING_M4 = False
33+
34+ # Perform a couple extra steps for the HalloWing M4
35+ try :
36+ if getattr (board , "CAP_PIN" ):
37+ IS_HALLOWING_M4 = True
38+ if getattr (board , "SPEAKER_ENABLE" ):
39+ # Enable the Speaker
40+ speaker_enable = digitalio .DigitalInOut (board .SPEAKER_ENABLE )
41+ speaker_enable .direction = digitalio .Direction .OUTPUT
42+ speaker_enable .value = True
43+ except AttributeError :
44+ pass
45+
3346AUDIO = audioio .AudioOut (board .A0 ) # Speaker
34- BACKLIGHT = pulseio .PWMOut (board .TFT_BACKLIGHT ) # Display backlight
47+
48+ board .DISPLAY .auto_brightness = False
3549
3650# Set up accelerometer on I2C bus, 4G range:
3751I2C = busio .I2C (board .SCL , board .SDA )
38- try :
39- ACCEL = adafruit_lis3dh .LIS3DH_I2C (I2C , address = 0x18 ) # Production board
40- except ValueError :
41- ACCEL = adafruit_lis3dh .LIS3DH_I2C (I2C , address = 0x19 ) # Beta hardware
42- ACCEL .range = adafruit_lis3dh .RANGE_4_G
52+ if IS_HALLOWING_M4 :
53+ import adafruit_msa301
54+ ACCEL = adafruit_msa301 .MSA301 (I2C )
55+ else :
56+ import adafruit_lis3dh
57+ try :
58+ ACCEL = adafruit_lis3dh .LIS3DH_I2C (I2C , address = 0x18 ) # Production board
59+ except ValueError :
60+ ACCEL = adafruit_lis3dh .LIS3DH_I2C (I2C , address = 0x19 ) # Beta hardware
61+ ACCEL .range = adafruit_lis3dh .RANGE_4_G
4362
4463STEP_INTERVAL_MIN = 0.3 # Shortest interval to walk one step (seconds)
4564STEP_INTERVAL_MAX = 2.0 # Longest interval to walk one step (seconds)
@@ -57,15 +76,15 @@ def load_wav(name):
5776# older CircuitPython) and the code will continue with the step detection.
5877try :
5978 import displayio
79+ board .DISPLAY .brightness = 0
6080 SCREEN = displayio .Group ()
6181 board .DISPLAY .show (SCREEN )
6282 BITMAP = displayio .OnDiskBitmap (open (IMAGEFILE , 'rb' ))
6383 SCREEN .append (
64- displayio .Sprite (BITMAP ,
65- pixel_shader = displayio .ColorConverter (),
66- position = (0 , 0 )))
67- board .DISPLAY .wait_for_frame () # Wait for the image to load.
68- BACKLIGHT .duty_cycle = 65535 # Turn on display backlight
84+ displayio .TileGrid (BITMAP ,
85+ pixel_shader = displayio .ColorConverter (),
86+ x = 0 , y = 0 ))
87+ board .DISPLAY .brightness = 1.0 # Turn on display backlight
6988except (ImportError , NameError , AttributeError ) as err :
7089 pass # Probably earlier CircuitPython; no displayio support
7190
0 commit comments