|
6 | 6 | """ |
7 | 7 |
|
8 | 8 | import time |
9 | | -import pulseio |
10 | 9 | import audioio |
11 | 10 | import busio |
12 | 11 | import board |
| 12 | +import digitalio |
13 | 13 | import touchio |
14 | | -import adafruit_lis3dh |
15 | 14 | import neopixel |
16 | 15 |
|
17 | 16 | def load_wav(name): |
@@ -39,32 +38,56 @@ def play_wav(wav): |
39 | 38 | JUMP_THRESHOLD = 4.0 # Higher number = triggers more easily |
40 | 39 | IMAGEFILE = 'mario.bmp' # BMP image to display |
41 | 40 |
|
| 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 | + |
42 | 59 | AUDIO = audioio.AudioOut(board.A0) # Speaker |
43 | | -BACKLIGHT = pulseio.PWMOut(board.TFT_BACKLIGHT) # Display backlight |
| 60 | + |
| 61 | +board.DISPLAY.auto_brightness = False |
44 | 62 | TOUCH1 = touchio.TouchIn(board.A2) # Capacitive touch pads |
45 | 63 | TOUCH2 = touchio.TouchIn(board.A3) |
46 | 64 | TOUCH3 = touchio.TouchIn(board.A4) |
47 | 65 | TOUCH4 = touchio.TouchIn(board.A5) |
48 | 66 |
|
49 | 67 | # Set up accelerometer on I2C bus, 4G range: |
50 | 68 | 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 |
56 | 79 |
|
57 | 80 | try: |
58 | 81 | import displayio |
| 82 | + board.DISPLAY.brightness = 0 |
59 | 83 | SCREEN = displayio.Group() |
60 | 84 | board.DISPLAY.show(SCREEN) |
61 | 85 | BITMAP = displayio.OnDiskBitmap(open(IMAGEFILE, 'rb')) |
62 | 86 | 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 |
68 | 91 | except (ImportError, NameError, AttributeError) as err: |
69 | 92 | pass # Probably earlier CircuitPython; no displayio support |
70 | 93 |
|
|
0 commit comments