Skip to content

Instantly share code, notes, and snippets.

@juanino
Created November 7, 2019 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanino/d27c1442592d59270ef513bfbacf5d13 to your computer and use it in GitHub Desktop.
Save juanino/d27c1442592d59270ef513bfbacf5d13 to your computer and use it in GitHub Desktop.
test mcp23017 - 9 of the 16 pins
#!/usr/bin/python3
import pprint
import board
import busio
from digitalio import Direction
from time import sleep
from adafruit_mcp230xx.mcp23017 import MCP23017
i2c = busio.I2C(board.SCL, board.SDA)
pp = pprint.PrettyPrinter(indent=4)
mcp = MCP23017(i2c)
pins = {}
for x in range(0,8):
pins[x]=mcp.get_pin(x)
pins[x].direction = Direction.OUTPUT
for x in range(0,8):
pins[x].value = True
print(x, pins[x].value)
sleep(.1)
for x in range(0,8):
pins[x].value = False
print(x, pins[x].value)
sleep(.1)
for x in range(0,99):
for x in range(0,8):
pins[x].value = True
print(x, pins[x].value)
sleep(.4)
for x in range(0,8):
pins[x].value = False
print(x, pins[x].value)
sleep(2)
sleep(1)
# the old twinkle loop
'''
while True:
for x in range(0,8):
pins[x].value = True
print(x, pins[x].value)
sleep(.1)
pins[x].value = False
sleep(.1)
'''
# pp.pprint(pins)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment