-
Notifications
You must be signed in to change notification settings - Fork 37
/
bearable.py
49 lines (40 loc) · 1.24 KB
/
bearable.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
import smbus
import time
DEV_ADDRESS = 0x15
class Bearable():
def __init__(self):
self.bus=smbus.SMBus(1)
self.leds = [0]*12
def enable_hack_mode(self, on=True):
if on:
self.bus.write_byte_data(DEV_ADDRESS,0,0x11)
else:
self.bus.write_byte_data(DEV_ADDRESS,0,0x10)
def set_led(self,number, brightness):
self.leds[number] = min(brightness,8)
def clear(self):
self.leds = [0]*12
self.update()
def update(self):
for i in range(0, len(self.leds), 2):
byte = self.leds[i]*16 +self.leds[i+1]
index = (i/2)+1
self.bus.write_byte_data(DEV_ADDRESS, index, byte)
if __name__=="__main__":
bear = Bearable()
bear.enable_hack_mode(True)
for i in range(6):
for j in range(8):
bear.set_led(i,j)
bear.set_led(i+6,j)
bear.update()
time.sleep(0.050)
for j in range(8):
bear.set_led(i, 7-j)
bear.set_led(i+6, 7-j)
bear.update()
time.sleep(0.050)
time.sleep(0.200)
bear.clear()
bear.update()
bear.enable_hack_mode(False)