-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrive.py
70 lines (44 loc) · 1.31 KB
/
drive.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
from tlc5947 import TLC5947
import time
from pyftdi import spi
# Instantiate a SPI controller
spi = spi.SpiController()
# AD0 should be connected to SCLK
# AD1 should be connected to MOSI (master out, slave in)
# AD4 should be connected to the second slave /CS, i
# Blank is tied to ground
# Configure the first interface (IF/1) of the first FTDI device as a
# SPI master
spi.configure('ftdi://::/1')
# Get a SPI port to a SPI slave w/ /CS on A*BUS3 and SPI mode 0 @ 12MHz
slave = spi.get_port(cs=0, freq=12E6, mode=0)
# Get GPIO port to manage extra pins, use A*BUS4 as GPO, A*BUS4 as GPI
gpio = spi.get_gpio()
# Assert GPO pin
class FakeGPIO(object):
def __init__(self, gpio):
self.g = gpio
self._value = False
def switch_to_output(self, value):
self.g.set_direction(0x30, 0x10)
@property
def value(self):
return self._value
@value.setter
def value(self, value):
if value == 0:
self.g.write(0x00)
self._value = False
else:
self.g.write(0x10)
self._value = True
tlc = TLC5947(slave, FakeGPIO(gpio))
def mkled(pin):
return tlc.create_pwm_out(pin)
leds = list(map(mkled, range(8)))
o = 5
while True:
leds[o].duty_cycle = 65535
time.sleep(1)
leds[o].duty_cycle = 0
time.sleep(1)