Skip to content

Instantly share code, notes, and snippets.

@theparticleman
Last active October 29, 2019 03:41
Show Gist options
  • Save theparticleman/133e9c488b26a96ea5aafe5fdf74fa3b to your computer and use it in GitHub Desktop.
Save theparticleman/133e9c488b26a96ea5aafe5fdf74fa3b to your computer and use it in GitHub Desktop.
import time
import board
import busio
import random
from adafruit_ht16k33 import matrix
i2c = busio.I2C(board.SCL, board.SDA)
matrix = matrix.Matrix8x8(i2c, auto_write=False)
matrix.fill(0)
col_max = 8
row_max = 8
blinkIndex = [1, 2, 3, 4, 3, 2, 1]
frames = [
[[0, 0, 1, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 1],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]]
]
def draw_image(matrix, image):
for col in range(col_max):
for row in range(row_max):
matrix[row, col] = image[row][col]
def draw_pupil(matrix, x, y):
x = int(x)
y = int(y)
matrix[x, y] = 0
matrix[x + 1, y] = 0
matrix[x, y + 1] = 0
matrix[x + 1, y + 1] = 0
blinkCountdown = 100
gazeCountdown = 75
gazeFrames = 50
pupilSpeed = 0.5
eyeX = 3
eyeY = 3
newX = 3
newY = 3
while True:
matrix.fill(0)
if blinkCountdown < len(blinkIndex):
currentImageIndex = blinkIndex[blinkCountdown]
else:
currentImageIndex = 0
draw_image(matrix, frames[currentImageIndex])
draw_pupil(matrix, eyeX, eyeY)
matrix.show()
blinkCountdown -= 1
if blinkCountdown <= 0:
blinkCountdown = random.randrange(5, 180)
gazeCountdown -= 1
if eyeX < newX :
eyeX += pupilSpeed
elif eyeX > newX :
eyeX -= pupilSpeed
if eyeY < newY :
eyeY += pupilSpeed
elif eyeY > newY :
eyeY -= pupilSpeed
if gazeCountdown <= 0 :
newX = random.randrange(2, 5)
newY = random.randrange(2, 5)
gazeCountdown = random.randrange(50, 120)
time.sleep(.03)
[Unit]
Description=Led service
[Service]
ExecStart=/usr/bin/python3 /home/pi/led-test/led-test.py
User=pi
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment