Skip to content

Commit a63e336

Browse files
authored
Merge pull request #1765 from FoamyGuy/magic_9_ball_cp7_odb
cp7 version of OnDiskBitmap usage for hallowing magic 9 ball
2 parents 48518a3 + 8d7a6fe commit a63e336

1 file changed

Lines changed: 53 additions & 42 deletions

File tree

Magic_Nine_Ball/magic_nine_ball.py

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,57 @@
2525

2626
while True:
2727
shaken = False
28-
with open(images[i], "rb") as f:
29-
print("Image load {}".format(images[i]))
30-
try:
31-
odb = displayio.OnDiskBitmap(f)
32-
except ValueError:
33-
print("Image unsupported {}".format(images[i]))
34-
del images[i]
35-
continue
36-
face = displayio.TileGrid(odb, pixel_shader=getattr(odb, 'pixel_shader', displayio.ColorConverter()))
37-
38-
splash.append(face)
39-
# Wait for the image to load.
28+
29+
print("Image load {}".format(images[i]))
30+
# CircuitPython 6 & 7 compatible
31+
try:
32+
f = open(images[i], "rb")
33+
odb = displayio.OnDiskBitmap(f)
34+
except ValueError:
35+
print("Image unsupported {}".format(images[i]))
36+
del images[i]
37+
continue
38+
face = displayio.TileGrid(odb, pixel_shader=getattr(odb, 'pixel_shader', displayio.ColorConverter()))
39+
40+
# # CircuitPython 7+ compatible
41+
# try:
42+
# odb = displayio.OnDiskBitmap(images[i])
43+
# except ValueError:
44+
# print("Image unsupported {}".format(images[i]))
45+
# del images[i]
46+
# continue
47+
# face = displayio.TileGrid(odb, pixel_shader=odb.pixel_shader)
48+
49+
splash.append(face)
50+
# Wait for the image to load.
51+
try:
52+
board.DISPLAY.refresh(target_frames_per_second=60)
53+
except AttributeError:
54+
board.DISPLAY.wait_for_frame()
55+
56+
# Fade up the backlight
57+
for b in range(101):
58+
board.DISPLAY.brightness = b / 100
59+
time.sleep(0.01) # default (0.01)
60+
61+
# Wait until the board gets shaken
62+
while not shaken:
4063
try:
41-
board.DISPLAY.refresh(target_frames_per_second=60)
42-
except AttributeError:
43-
board.DISPLAY.wait_for_frame()
44-
45-
# Fade up the backlight
46-
for b in range(101):
47-
board.DISPLAY.brightness = b / 100
48-
time.sleep(0.01) # default (0.01)
49-
50-
# Wait until the board gets shaken
51-
while not shaken:
52-
try:
53-
ACCEL_Z = ACCEL.acceleration[2] # Read Z axis acceleration
54-
except OSError:
55-
pass
56-
# print(ACCEL_Z) # uncomment to see the accelerometer z reading
57-
if ACCEL_Z > SENSITIVITY:
58-
shaken = True
59-
60-
# Fade down the backlight
61-
for b in range(100, 0, -1):
62-
board.DISPLAY.brightness = b
63-
time.sleep(0.005) # default (0.005)
64-
65-
splash.pop()
66-
67-
i = random.randint(0, (len(images)-1)) # pick a new random image
68-
# print("shaken")
69-
faceup = False
70-
i %= len(images) - 1
64+
ACCEL_Z = ACCEL.acceleration[2] # Read Z axis acceleration
65+
except OSError:
66+
pass
67+
# print(ACCEL_Z) # uncomment to see the accelerometer z reading
68+
if ACCEL_Z > SENSITIVITY:
69+
shaken = True
70+
71+
# Fade down the backlight
72+
for b in range(100, 0, -1):
73+
board.DISPLAY.brightness = b
74+
time.sleep(0.005) # default (0.005)
75+
76+
splash.pop()
77+
78+
i = random.randint(0, (len(images)-1)) # pick a new random image
79+
# print("shaken")
80+
faceup = False
81+
i %= len(images) - 1

0 commit comments

Comments
 (0)