Update OnDiskBitmap code to take a filename string with CP7
Replace board.A0 with board.SPEAKER Replace board.A... with board.TOUCH... Replace busio.I2C(...) with board.I2C()
This commit is contained in:
parent
a7e689287d
commit
689a324214
2 changed files with 40 additions and 31 deletions
|
|
@ -1,14 +1,12 @@
|
|||
"""
|
||||
Jump & touch sound example for Adafruit Hallowing. Plays different sounds
|
||||
in response to jumping and capacitive touch pads.
|
||||
Image display requires CircuitPython 4.0.0-alpha1 or later (with displayio
|
||||
support). WILL work with earlier versions, just no image shown!
|
||||
"""
|
||||
|
||||
import time
|
||||
import busio
|
||||
import board
|
||||
import digitalio
|
||||
import displayio
|
||||
import audioio
|
||||
import audiocore
|
||||
import touchio
|
||||
|
|
@ -57,16 +55,16 @@ try:
|
|||
except AttributeError:
|
||||
pass
|
||||
|
||||
AUDIO = audioio.AudioOut(board.A0) # Speaker
|
||||
AUDIO = audioio.AudioOut(board.SPEAKER) # Speaker
|
||||
|
||||
board.DISPLAY.auto_brightness = False
|
||||
TOUCH1 = touchio.TouchIn(board.A2) # Capacitive touch pads
|
||||
TOUCH2 = touchio.TouchIn(board.A3)
|
||||
TOUCH3 = touchio.TouchIn(board.A4)
|
||||
TOUCH4 = touchio.TouchIn(board.A5)
|
||||
TOUCH1 = touchio.TouchIn(board.TOUCH1) # Capacitive touch pads
|
||||
TOUCH2 = touchio.TouchIn(board.TOUCH2)
|
||||
TOUCH3 = touchio.TouchIn(board.TOUCH3)
|
||||
TOUCH4 = touchio.TouchIn(board.TOUCH4)
|
||||
|
||||
# Set up accelerometer on I2C bus, 4G range:
|
||||
I2C = busio.I2C(board.SCL, board.SDA)
|
||||
I2C = board.I2C()
|
||||
if IS_HALLOWING_M4:
|
||||
import adafruit_msa301
|
||||
ACCEL = adafruit_msa301.MSA301(I2C)
|
||||
|
|
@ -79,18 +77,25 @@ else:
|
|||
ACCEL.range = adafruit_lis3dh.RANGE_4_G
|
||||
|
||||
try:
|
||||
import displayio
|
||||
board.DISPLAY.brightness = 0
|
||||
SCREEN = displayio.Group()
|
||||
board.DISPLAY.show(SCREEN)
|
||||
|
||||
# CircuitPython 6 & 7 compatible
|
||||
BITMAP = displayio.OnDiskBitmap(open(IMAGEFILE, 'rb'))
|
||||
SCREEN.append(
|
||||
displayio.TileGrid(BITMAP,
|
||||
pixel_shader=getattr(BITMAP, 'pixel_shader', displayio.ColorConverter()),
|
||||
x=0, y=0))
|
||||
board.DISPLAY.brightness = 1.0
|
||||
except (ImportError, NameError, AttributeError) as err:
|
||||
pass # Probably earlier CircuitPython; no displayio support
|
||||
TILEGRID = displayio.TileGrid(
|
||||
BITMAP,
|
||||
pixel_shader=getattr(BITMAP, 'pixel_shader', displayio.ColorConverter())
|
||||
)
|
||||
|
||||
# # CircuitPython 7+ compatible
|
||||
# BITMAP = displayio.OnDiskBitmap(IMAGEFILE)
|
||||
# TILEGRID = displayio.TileGrid(BITMAP, pixel_shader=BITMAP.pixel_shader)
|
||||
|
||||
SCREEN.append(TILEGRID)
|
||||
board.DISPLAY.brightness = 1.0 # Turn on display backlight
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
|
||||
# If everything has initialized correctly, turn off the onboard NeoPixel:
|
||||
PIXEL = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0)
|
||||
|
|
|
|||
|
|
@ -4,15 +4,13 @@ pedometer, plays different sounds in response to steps & jumps. Step
|
|||
detection based on "Full-Featured Pedometer Design Realized with 3-Axis
|
||||
Digital Accelerometer" by Neil Zhao, Analog Dialogue Technical Journal,
|
||||
June 2010.
|
||||
Image display requires CircuitPython 4.0.0-alpha1 or later (with displayio
|
||||
support). WILL work with earlier versions, just no image shown!
|
||||
"""
|
||||
|
||||
import time
|
||||
import math
|
||||
import digitalio
|
||||
import displayio
|
||||
import board
|
||||
import busio
|
||||
import audioio
|
||||
import audiocore
|
||||
import neopixel
|
||||
|
|
@ -44,12 +42,12 @@ try:
|
|||
except AttributeError:
|
||||
pass
|
||||
|
||||
AUDIO = audioio.AudioOut(board.A0) # Speaker
|
||||
AUDIO = audioio.AudioOut(board.SPEAKER) # Speaker
|
||||
|
||||
board.DISPLAY.auto_brightness = False
|
||||
|
||||
# Set up accelerometer on I2C bus, 4G range:
|
||||
I2C = busio.I2C(board.SCL, board.SDA)
|
||||
I2C = board.I2C()
|
||||
if IS_HALLOWING_M4:
|
||||
import adafruit_msa301
|
||||
ACCEL = adafruit_msa301.MSA301(I2C)
|
||||
|
|
@ -73,21 +71,27 @@ FILTER_BUF = [0] * FILTER_SIZE
|
|||
FILTER_SUM = 0 # Initial average value
|
||||
FILTER_INDEX = 0 # Current position in sample-averaging buffer
|
||||
|
||||
# Display BMP image. If this fails, it's not catastrophic (probably just
|
||||
# older CircuitPython) and the code will continue with the step detection.
|
||||
# Display BMP image.
|
||||
try:
|
||||
import displayio
|
||||
board.DISPLAY.brightness = 0
|
||||
SCREEN = displayio.Group()
|
||||
board.DISPLAY.show(SCREEN)
|
||||
|
||||
# CircuitPython 6 & 7 compatible
|
||||
BITMAP = displayio.OnDiskBitmap(open(IMAGEFILE, 'rb'))
|
||||
SCREEN.append(
|
||||
displayio.TileGrid(BITMAP,
|
||||
pixel_shader=getattr(BITMAP, 'pixel_shader', displayio.ColorConverter()),
|
||||
x=0, y=0))
|
||||
TILEGRID = displayio.TileGrid(
|
||||
BITMAP,
|
||||
pixel_shader=getattr(BITMAP, 'pixel_shader', displayio.ColorConverter())
|
||||
)
|
||||
|
||||
# # CircuitPython 7+ compatible
|
||||
# BITMAP = displayio.OnDiskBitmap(IMAGEFILE)
|
||||
# TILEGRID = displayio.TileGrid(BITMAP, pixel_shader=BITMAP.pixel_shader)
|
||||
|
||||
SCREEN.append(TILEGRID)
|
||||
board.DISPLAY.brightness = 1.0 # Turn on display backlight
|
||||
except (ImportError, NameError, AttributeError) as err:
|
||||
pass # Probably earlier CircuitPython; no displayio support
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
|
||||
# If everything has initialized correctly, turn off the onboard NeoPixel:
|
||||
PIXEL = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue