Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def loop():
old_first = False
old_left = False
old_right = False
old_last = False
index = 0
while True:
# POLL BUTTONS
# remember they are inverted
first = not GPIO.input(BUTTON_FIRST)
left = not GPIO.input(BUTTON_LEFT)
right = not GPIO.input(BUTTON_RIGHT)
last = not GPIO.input(BUTTON_LAST)
# REPORT ANY CHANGED BUTTONS
if first != old_first:
print("FIRST=" + str(first))
old_first = first
if left != old_left:
print("LEFT=" + str(left))
old_left = left
if right != old_right:
print("RIGHT=" + str(right))
old_right = right
if last != old_last:
print("LAST=" + str(last))
old_last = last
# FLASH PRESENTLY SELECTED LED
GPIO.output(LED_GPIO[index], True)
time.sleep(FLASH_TIME/2)
GPIO.output(LED_GPIO[index], False)
time.sleep(FLASH_TIME/2)
# MAIN PROGRAM
try:
setup()
loop()
finally:
GPIO.cleanup()
import anyio.seg7 as display
import time
# Use this for Raspberry Pi
#import RPi.GPIO as GPIO
#LED_PINS = [10,22,25,8,7,9,11,15]
# Use this for Arduino
import anyio.GPIO as GPIO
LED_PINS = [7,6,14,16,10,8,9,15]
GPIO.setmode(GPIO.BCM)
ON = False # common-anode. Set to True for a common cathode display
display.setup(GPIO, LED_PINS, ON)
try:
while True:
for d in range(10):
display.write(str(d))
time.sleep(0.5)
finally:
GPIO.cleanup()