Skip to content

Instantly share code, notes, and snippets.

@shapr
Last active December 23, 2015 02:29
Show Gist options
  • Save shapr/6567560 to your computer and use it in GitHub Desktop.
Save shapr/6567560 to your computer and use it in GitHub Desktop.
first hack at charlieplexing with Adafruit_BBIO
import Adafruit_BBIO.GPIO as GPIO
import time
pins = ["P8_12","P8_14","P8_16","P8_18","P8_20","P8_22"]
for p in pins:
GPIO.setup(p, GPIO.OUT)
def setnums(n):
listvals = []
bitstring = bin(n)[2:]
for x in bitstring:
if x == '0':
listvals.append(0)
else:
listvals.append(1)
while(len(listvals) < 6):
listvals = [0] + listvals
return listvals
def setpins(values):
# input should be like [1,0,1,0,1,0]
for x in xrange(0,6): # assume a list of length six, containing only boolean values
if values[x]:
GPIO.output(pins[x],GPIO.HIGH)
else:
GPIO.output(pins[x],GPIO.LOW)
for n in xrange(0,64):
l = setnums(n)
setpins(l)
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment