Skip to content

Instantly share code, notes, and snippets.

@rsbohn
Last active January 15, 2022 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsbohn/d053e2b6804f651615c9f62ae1b9d3af to your computer and use it in GitHub Desktop.
Save rsbohn/d053e2b6804f651615c9f62ae1b9d3af to your computer and use it in GitHub Desktop.
# SPDX-FileCopyrightText: Copyright (c) 2022 Randall Bohn (dexter)
#
# SPDX-License-Identifier: MIT
#
# Dice Roller
# Runs on Feather Bluefruit Sense nRF52840
# faces: a 336x48 sprite sheet
import board
import time
import displayio
import neopixel
import random
from adafruit_displayio_sh1107 import SH1107
from adafruit_apds9960.apds9960 import APDS9960
import adafruit_fancyled.adafruit_fancyled as fancy
neo = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.3)
neo.fill(0)
displayio.release_displays()
i2c = board.I2C()
bus = displayio.I2CDisplay(i2c, device_address=0x3C)
display = SH1107(bus, width=128, height=64, rotation=0)
faces = displayio.OnDiskBitmap('/images/faces.bmp')
facegrid = displayio.TileGrid(faces, pixel_shader=faces.pixel_shader,
width=2, height=1,
tile_width=48, tile_height=48,
x = 16, y=8
)
facegrid[0]=6
facegrid[1]=6
splash = displayio.Group()
splash.append(facegrid)
display.show(splash)
apds = APDS9960(i2c)
apds.enable_proximity = True
gradient = [fancy.CRGB(0,64,0),fancy.CRGB(0,0,0)]
def spread(duration):
et = time.monotonic() + duration
while et > time.monotonic():
t = et - time.monotonic()
yield 1 - t/duration
while True:
if apds.proximity > 5:
neo.fill(0x880088)
facegrid[0] = 6
facegrid[1] = 6
for v in spread(0.5):
pass
for v in spread(2):
neo.fill(fancy.palette_lookup(gradient, v/2).pack())
facegrid[0,0] = random.randrange(6)
facegrid[1,0] = random.randrange(6)
neo.fill(0)
time.sleep(0.01)
@rsbohn
Copy link
Author

rsbohn commented Jan 15, 2022

Display is https://www.adafruit.com/product/4650 128x64 OLED.
Both boards in a Feather Doubler https://www.adafruit.com/product/2890

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment