Last active
December 23, 2015 02:29
-
-
Save shapr/6567560 to your computer and use it in GitHub Desktop.
first hack at charlieplexing with Adafruit_BBIO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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