forked from romilly/quick2wire-python-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti-counter
More file actions
executable file
·29 lines (21 loc) · 766 Bytes
/
multi-counter
File metadata and controls
executable file
·29 lines (21 loc) · 766 Bytes
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
#!/usr/bin/env python3
# demo will drive multiple MCP23017 devices at different addresses
# see http://quick2wire.com/2012/12/see-the-new-boards-at-work-with-blinken-bars/ for demo
from time import sleep
from itertools import cycle
import sys
import quick2wire.i2c as i2c
from quick2wire.parts.mcp23017 import Registers as MCP23017Registers
from quick2wire.parts.mcp23x17 import IODIRB, GPIO
offset = int(sys.argv[1]) if len(sys.argv) > 1 else 0
address = 0x20 + offset
with i2c.I2CMaster() as bus:
chip = MCP23017Registers(bus, address)
chip.reset()
chip.write_register(IODIRB, 0x00)
try:
for count in cycle(range(256)):
chip.write_banked_register(1, GPIO, count)
sleep(0.1)
finally:
chip.reset()