Created
August 7, 2017 06:41
-
-
Save aniline/c17e0fef792f03c0bc50682b1fcdb0fd to your computer and use it in GitHub Desktop.
An old script (better here than in Dropbox, dunno what it does).
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
#!python | |
import RPi.GPIO as GPIO | |
import time | |
import sys | |
GPIO.setmode(GPIO.BOARD) | |
bint = 3 | |
bits_channel = [5, 7, 11, 13] | |
GPIO.setup(bint, GPIO.IN) | |
map(lambda x: GPIO.setup(x, GPIO.IN), bits_channel) | |
toeprev = False | |
number = "" | |
last_code_time = 0 | |
number_dispatched = True | |
number_ready = False | |
while True: | |
toe = GPIO.input(bint) | |
if (toe != toeprev): | |
if toe: | |
sys.stdout.write('X') | |
sys.stdout.flush() | |
digit_n = eval('0b'+reduce(lambda x, y: x + y, map (str, map (GPIO.input, bits_channel)))) | |
if ((digit_n > 9) and (digit_n < 16)): | |
digit = ['0','*','#','A','B','C','D'][(digit_n - 10)] | |
else: | |
digit = str(digit_n) | |
if ((time.time () - last_code_time) > 2): | |
number_dispatched = False | |
number = digit | |
else: | |
number = number + digit | |
last_code_time = time.time() | |
else: | |
sys.stdout.write('.') | |
sys.stdout.flush() | |
toeprev = toe | |
if (not number_dispatched) and ((time.time() - last_code_time) > 2): | |
print "Number > ", number | |
number_dispatched = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment