import sys, time import RPi.GPIO as GPIO from datetime import datetime, timedelta # Digispark specific import usb # 1.0, *NOT* 0.4: use *pip install pyusb* to install from arduino.usbdevice import ArduinoUsbDevice combo = [] master_Combo = [] red_LED = 24 green_LED = 25 GPIO.cleanup() GPIO.setmode(GPIO.BCM) GPIO.setup(red_LED, GPIO.OUT) GPIO.setup(green_LED, GPIO.OUT) def readCombo(): v_combo = [] fb_store='0' while True: try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) except: print "Dial not found! Attach your Digispark (with a dial) and rerun." GPIO.cleanup() sys.exit(0) try: feedback="" while True: lastChar=chr(theDevice.read()) if lastChar=="\n": break feedback=feedback+lastChar print(feedback) # Comment this line in production fb_store=feedback[0] start_time=datetime.now() except: # Check if time on number is greater than 5 seconds try: elapsed_time=datetime.now()-start_time if elapsed_time.seconds > 5: v_combo.append(fb_store) blinkLED(green_LED, 2, 0.2) start_time=datetime.now() if len(v_combo)==len(master_Combo): break except: time.sleep(0.1) return v_combo def blinkLED(v_LED, times, speed): GPIO.output(v_LED, GPIO.LOW) for i in range(times): GPIO.output(v_LED, GPIO.HIGH) time.sleep(speed) GPIO.output(v_LED, GPIO.LOW) time.sleep(speed) if __name__ == "__main__": if len(sys.argv)==1: print "Please input code combination." else: # Read combo from command line master_Combo=sys.argv[1:] while True: combo=readCombo() if combo==master_Combo: blinkLED(green_LED, 3, 0.3) break else: blinkLED(red_LED, 3, 0.3) GPIO.cleanup()