Skip to content

Commit 0b6b216

Browse files
authored
Merge pull request adafruit#948 from makermelissa/master
Updated many examples for displayio to work in CP 4 and 5
2 parents 1818d3f + 1ffdb6e commit 0b6b216

File tree

18 files changed

+147
-55
lines changed

18 files changed

+147
-55
lines changed

CircuitPython_PyPaint/code.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ def set_cursor_bitmap(self, bmp):
146146
self.poke()
147147

148148
################################################################################
149-
150149
class Paint(object):
151150

151+
#pylint:disable=too-many-statements
152152
def __init__(self, display=board.DISPLAY):
153153
self._logger = logging.getLogger("Paint")
154154
self._logger.setLevel(logging.DEBUG)
@@ -196,9 +196,13 @@ def __init__(self, display=board.DISPLAY):
196196
self._splash.append(self._palette)
197197

198198
self._display.show(self._splash)
199-
self._display.refresh_soon()
200-
gc.collect()
201-
self._display.wait_for_frame()
199+
try:
200+
gc.collect()
201+
self._display.refresh(target_frames_per_second=60)
202+
except AttributeError:
203+
self._display.refresh_soon()
204+
gc.collect()
205+
self._display.wait_for_frame()
202206

203207
self._brush = 0
204208
self._cursor_bitmaps = [self._cursor_bitmap_1(), self._cursor_bitmap_3()]
@@ -215,6 +219,7 @@ def __init__(self, display=board.DISPLAY):
215219
self._last_location = None
216220

217221
self._pencolor = 7
222+
#pylint:enable=too-many-statements
218223

219224
def _make_palette(self):
220225
self._palette_bitmap = displayio.Bitmap(self._w // 10, self._h, 5)

CircuitPython_displayio/displayio_display_driver.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@
3737
group = displayio.Group()
3838
group.append(tile_grid)
3939
display.show(group)
40-
display.refresh_soon()

CircuitPython_displayio/displayio_display_manual.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,3 @@
6464
group = displayio.Group()
6565
group.append(tile_grid)
6666
display.show(group)
67-
display.refresh_soon()

CircuitPython_displayio/displayio_parallelbus.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,3 @@
6262
group = displayio.Group()
6363
group.append(tile_grid)
6464
display.show(group)
65-
display.refresh_soon()

HalloWing_Cat_Toy/code.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ def show_image(filename):
7575
face = displayio.Sprite(odb, pixel_shader=displayio.ColorConverter(), position=(0, 0))
7676
backlight.value = False
7777
splash.append(face)
78-
board.DISPLAY.wait_for_frame()
78+
try:
79+
board.DISPLAY.refresh(target_frames_per_second=60)
80+
except AttributeError:
81+
board.DISPLAY.wait_for_frame()
7982
backlight.value = True
8083

8184

HalloWing_Jump_Scare_Trap/hallowing_jump_scare_trap.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ def show_image(filename):
9999
backlight.duty_cycle = 0
100100
splash.append(face)
101101
# Wait for the image to load.
102-
board.DISPLAY.wait_for_frame()
102+
try:
103+
board.DISPLAY.refresh(target_frames_per_second=60)
104+
except AttributeError:
105+
board.DISPLAY.wait_for_frame()
103106
backlight.duty_cycle = max_brightness
104107

105108
beep(1) # startup beep

HalloWing_Tour_Guide/code.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ def show_image(filename):
6868
face = displayio.Sprite(odb, pixel_shader=displayio.ColorConverter(), position=(0, 0))
6969
backlight.value = False
7070
splash.append(face)
71-
board.DISPLAY.wait_for_frame()
71+
try:
72+
board.DISPLAY.refresh(target_frames_per_second=60)
73+
except AttributeError:
74+
board.DISPLAY.wait_for_frame()
7275
backlight.value = True
7376

7477

Hallowing_Jump_Sound/jump-sound.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"""
77

88
import time
9-
import audioio
109
import busio
1110
import board
1211
import digitalio
12+
import audioio
1313
import touchio
1414
import neopixel
1515

Hallowing_Jump_Sound/stomp-and-roar.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
import time
1212
import math
13+
import digitalio
1314
import board
1415
import busio
1516
import audioio
16-
import pulseio
1717
import neopixel
18-
import adafruit_lis3dh
1918

2019
def load_wav(name):
2120
"""
@@ -30,16 +29,36 @@ def load_wav(name):
3029
ROAR_WAV = load_wav('roar') # WAV when jumping
3130
IMAGEFILE = '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+
3346
AUDIO = 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:
3751
I2C = 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

4463
STEP_INTERVAL_MIN = 0.3 # Shortest interval to walk one step (seconds)
4564
STEP_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.
5877
try:
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
6988
except (ImportError, NameError, AttributeError) as err:
7089
pass # Probably earlier CircuitPython; no displayio support
7190

Magic_Nine_Ball/magic_nine_ball.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737

3838
splash.append(face)
3939
# Wait for the image to load.
40-
board.DISPLAY.wait_for_frame()
40+
try:
41+
board.DISPLAY.refresh(target_frames_per_second=60)
42+
except AttributeError:
43+
board.DISPLAY.wait_for_frame()
4144

4245
# Fade up the backlight
4346
for b in range(101):

0 commit comments

Comments
 (0)