Fix up typos

This commit is contained in:
James Bowman 2020-03-18 20:31:49 -07:00
parent fa174554ef
commit 8d57af5961
1 changed files with 15 additions and 7 deletions

View File

@ -1,26 +1,34 @@
import sys
import time
import random
import struct
from i2cdriver import I2CDriver
class PCA9685:
def __init__(self, i2, a = 0x40):
self.i2 = i2
self.a = a
self.regwr(self.a, 0x00, 0x20) # auto-increment mode
self.i2.regwr(self.a, 0x00, 0x20) # auto-increment mode
def set(self, channel, t_on, t_off):
assert 0 <= channel < 16
assert 0 <= ton <= 0x1000
assert 0 <= toff <= 0x1000
self.regwr(self.a,
0x06 + 4 * channel,
struct.pack("<HH", t_on, t_off))
assert 0 <= t_on <= 0x1000
assert 0 <= t_off <= 0x1000
self.i2.regwr(self.a,
0x06 + 4 * channel,
struct.pack("<HH", t_on, t_off))
if __name__ == '__main__':
i2 = I2CDriver(sys.argv[1])
print(i2.scan())
d = PCA9685(i2)
for channel in range(16):
d.set(channel, 4096, 0)
while True:
for channel in range(16):
d.set(channel, random.randrange(4096), random.randrange(4096))
time.sleep(1)
time.sleep(.3)