Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 53 additions & 42 deletions Magic_Nine_Ball/magic_nine_ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,57 @@

while True:
shaken = False
with open(images[i], "rb") as f:
print("Image load {}".format(images[i]))
try:
odb = displayio.OnDiskBitmap(f)
except ValueError:
print("Image unsupported {}".format(images[i]))
del images[i]
continue
face = displayio.TileGrid(odb, pixel_shader=getattr(odb, 'pixel_shader', displayio.ColorConverter()))

splash.append(face)
# Wait for the image to load.

print("Image load {}".format(images[i]))
# CircuitPython 6 & 7 compatible
try:
f = open(images[i], "rb")
odb = displayio.OnDiskBitmap(f)
except ValueError:
print("Image unsupported {}".format(images[i]))
del images[i]
continue
face = displayio.TileGrid(odb, pixel_shader=getattr(odb, 'pixel_shader', displayio.ColorConverter()))

# # CircuitPython 7+ compatible
# try:
# odb = displayio.OnDiskBitmap(images[i])
# except ValueError:
# print("Image unsupported {}".format(images[i]))
# del images[i]
# continue
# face = displayio.TileGrid(odb, pixel_shader=odb.pixel_shader)

splash.append(face)
# Wait for the image to load.
try:
board.DISPLAY.refresh(target_frames_per_second=60)
except AttributeError:
board.DISPLAY.wait_for_frame()

# Fade up the backlight
for b in range(101):
board.DISPLAY.brightness = b / 100
time.sleep(0.01) # default (0.01)

# Wait until the board gets shaken
while not shaken:
try:
board.DISPLAY.refresh(target_frames_per_second=60)
except AttributeError:
board.DISPLAY.wait_for_frame()

# Fade up the backlight
for b in range(101):
board.DISPLAY.brightness = b / 100
time.sleep(0.01) # default (0.01)

# Wait until the board gets shaken
while not shaken:
try:
ACCEL_Z = ACCEL.acceleration[2] # Read Z axis acceleration
except OSError:
pass
# print(ACCEL_Z) # uncomment to see the accelerometer z reading
if ACCEL_Z > SENSITIVITY:
shaken = True

# Fade down the backlight
for b in range(100, 0, -1):
board.DISPLAY.brightness = b
time.sleep(0.005) # default (0.005)

splash.pop()

i = random.randint(0, (len(images)-1)) # pick a new random image
# print("shaken")
faceup = False
i %= len(images) - 1
ACCEL_Z = ACCEL.acceleration[2] # Read Z axis acceleration
except OSError:
pass
# print(ACCEL_Z) # uncomment to see the accelerometer z reading
if ACCEL_Z > SENSITIVITY:
shaken = True

# Fade down the backlight
for b in range(100, 0, -1):
board.DISPLAY.brightness = b
time.sleep(0.005) # default (0.005)

splash.pop()

i = random.randint(0, (len(images)-1)) # pick a new random image
# print("shaken")
faceup = False
i %= len(images) - 1