Skip to content

Instantly share code, notes, and snippets.

@robsongomes
Last active September 4, 2015 21:42
Show Gist options
  • Save robsongomes/b337fced17ca5dca85b0 to your computer and use it in GitHub Desktop.
Save robsongomes/b337fced17ca5dca85b0 to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
import time
#1
PINS = [7,15,16]
PIN_BTN = 19
COUNTER = 0
MAX_COUNT = 7
GPIO.setmode(GPIO.BOARD)
def Setup():
#2
GPIO.setup(PIN_BTN,GPIO.IN)
for p in PINS:
GPIO.setup(p,GPIO.OUT)
def Display(bits):
bits = bits.zfill(3)
print "Displaying " + bits
for i in range(len(bits)):
GPIO.output(PINS[i],int(bits[i]))
def Count():
global COUNTER
#3
if ( GPIO.input(PIN_BTN) == False):
COUNTER += 1
if ( COUNTER > MAX_COUNT ):
COUNTER = 0
bin_number = bin(int(COUNTER))
print "Sending the number " + str(COUNTER)
time.sleep(0.500)
Display(bin_number[2:])
def loop():
try:
while True:
Count()
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