Skip to content

Instantly share code, notes, and snippets.

@robsongomes
Last active September 4, 2015 02:03
Show Gist options
  • Save robsongomes/dd5ccb69af8b5f9319ef to your computer and use it in GitHub Desktop.
Save robsongomes/dd5ccb69af8b5f9319ef to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
import time
#1
PINS = [7,15,16]
COUNTER = 0
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
def Setup():
for p in PINS:
GPIO.setup(p,GPIO.OUT)
def Display(bits):
#2
bits = bits.zfill(3)
for i in range(len(bits)):
GPIO.output(PINS[i],int(bits[i]))
def Count():
global COUNTER
COUNTER += 1
if (COUNTER > 7):
COUNTER = 0
#3
bin_number = bin(int(COUNTER))
Display(bin_number[2:])
time.sleep(1)
def loop():
try:
while True:
Count()
#4
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
Setup()
loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment