-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions_leds.py
executable file
·104 lines (87 loc) · 2.45 KB
/
actions_leds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import random
import time
import board
import adafruit_dotstar as dotstar
# Using a DotStar Digital LED Matrix with 64 LEDs connected to digital pins
dots = dotstar.DotStar(board.D13, board.D12, 64, brightness=0.1)
# Using a Respeaker 2-Mics Pi Hat with its 3 APA102 LEDs connected to hardware SPI
# chest = dotstar.DotStar(board.SCK, board.MOSI, 3, brightness=0.2)
class LEDs(object):
"""Class used to set up
face LED-matrix animations
"""
"""
def initialize_pi_hat_leds():
# a random bright 0 -> 224
def random_bright():
return random.randrange(0, 7) * 32
# MAIN LOOP
num = 1
n_chest = len(chest)
while num < 10: # seqquence length
# Fill each dot with a random bright
for dot in range(n_chest):
chest[dot] = (0, 0, random_bright())
num = num + 1
time.sleep(.05) # flicker length
for dot in range(n_chest):
chest[dot] = (0, 0, 255)
"""
def initialize_matrix():
dots.fill((0, 0, 0))
def initialize_face():
# Left eye
dots[49] = (255, 255, 255)
dots[50] = (255, 255, 255)
dots[57] = (255, 255, 255)
dots[58] = (255, 255, 255)
# Right eye
dots[53] = (255, 255, 255)
dots[54] = (255, 255, 255)
dots[61] = (255, 255, 255)
dots[62] = (255, 255, 255)
# Main part of mouth
dots[18] = (255, 255, 255)
dots[19] = (255, 255, 255)
dots[20] = (255, 255, 255)
dots[21] = (255, 255, 255)
dots[10] = (255, 255, 255)
dots[11] = (255, 255, 255)
dots[12] = (255, 255, 255)
dots[13] = (255, 255, 255)
# Neutral expression
dots[16] = (255, 255, 255)
dots[17] = (255, 255, 255)
dots[22] = (255, 255, 255)
dots[23] = (255, 255, 255)
def smile():
dots[16] = (0, 0, 0)
dots[24] = (255, 255, 255)
dots[31] = (255, 255, 255)
dots[23] = (0, 0, 0)
def straight_face():
dots[16] = (255, 255, 255)
dots[24] = (0, 0, 0)
dots[31] = (0, 0, 0)
dots[8] = (0, 0, 0)
dots[15] = (0, 0, 0)
dots[23] = (255, 255, 255)
def frown():
dots[8] = (255, 255, 255)
dots[16] = (0, 0, 0)
dots[23] = (0, 0, 0)
dots[15] = (255, 255, 255)
def wink():
dots[61] = (0, 0, 0)
dots[62] = (0, 0, 0)
time.sleep(.05)
dots[53] = (0, 0, 0)
dots[54] = (0, 0, 0)
time.sleep(.05)
dots[53] = (255, 255, 255)
dots[54] = (255, 255, 255)
time.sleep(.05)
dots[61] = (255, 255, 255)
dots[62] = (255, 255, 255)