-
Notifications
You must be signed in to change notification settings - Fork 0
/
suit.py
70 lines (58 loc) · 1.93 KB
/
suit.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
import neopixel
from machine import Pin
import uasyncio as asyncio
class Suit:
teamcolors=[
(0, 0, 255),
(0, 255, 0),
(255, 0, 255)
]
def __init__(self, team, neopixel_pin_number, neopixel_count):
self.team = team
self.neopixel_count = neopixel_count
self.setup_pins(neopixel_pin_number)
self.fill_color(self.get_team_color(team))
def setup_pins(self, neopixel_pin_number):
np_pin = Pin(neopixel_pin_number, Pin.OUT)
self.np = neopixel.NeoPixel(np_pin, self.neopixel_count)
def reset():
self.should_blink = False
self.blackout()
def fill_color(self, color):
for i in range(0, self.neopixel_count):
self.np[i] = color
self.np.write()
def alternate_color(self, color):
for i in range(0, self.neopixel_count):
if i % 2 == 0:
self.np[i] = color
else:
self.np[i] = (0,0,0)
self.np.write()
#functions
def blackout(self):
for i in range(0, self.neopixel_count):
self.np[i] = (0,0,0)
self.np.write()
async def defeated(self):
color = self.get_team_color(self.team)
self.should_blink = True
while self.should_blink:
self.alternate_color(color)
await asyncio.sleep(1)
self.blackout();
await asyncio.sleep(1)
self.blackout()
async def single_flash(self, team):
self.blackout()
await asyncio.sleep_ms(20)
self.fill_color(self.get_team_color(team))
await asyncio.sleep_ms(100)
self.fill_color(self.get_team_color(self.team))
def get_team_color(self, team):
if team <= len(self.teamcolors) and team > 0:
return self.teamcolors[self.team -1]
else:
raise Exception("Zero or negative teams are not allowed")
def __del__(self):
del self.np