# python3 # Steady hands game # run with - sudo python3 Steady.py import RPi.GPIO as GPIO # get the library to access the GPIO pins import time # use BCM GPIO numbering - use anything else and you are an idiot! GPIO.setmode(GPIO.BCM) # set up GPIO input pins # (pull_up_down be PUD_OFF, PUD_UP or PUD_DOWN, default PUD_OFF) GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP) # GPIO 0 & 1 have hardware pull ups fitted in the Pi so don't enable them GPIO.setup(0, GPIO.IN, pull_up_down=GPIO.PUD_OFF) GPIO.setup(1, GPIO.IN, pull_up_down=GPIO.PUD_OFF) # uncomment these next two lines if you have an issue 2 board #GPIO.setup(2, GPIO.IN, pull_up_down=GPIO.PUD_OFF) #GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_OFF) print("Hi from Python :- Steady Hands game") start_rest = 4 end_rest = 0 # change to 2 if you have an issue 2 board wire = 1 # change to 3 if you have an issue 2 board while True: #1) Wait until the loop is placed on the start rest. print("Move the loop to the start rest") while GPIO.input(start_rest) != 0: # returns 0 when loop is on the start rest time.sleep(0.8) #now we are at the start of the bent wire print("Start when you are ready") #2) Wait until the loop is removed from the start rest. while GPIO.input(start_rest) == 0: # returns 0 when loop is on the start rest time.sleep(0.1) print("Your off") #3) Time the interval from lifting it off the start rest until it reaches the end penalty = 0 run_time = time.clock() while GPIO.input(end_rest) != 0: #returns 0 when loop is on the end rest if GPIO.input(wire) == 0: #returns 0 when the loop is touching the wire penalty = penalty + 1 print("Penalties total", penalty, " points") time.sleep(0.07) score = time.clock() - run_time + (penalty * 0.07) print("The run time was", score, "seconds with", penalty, "Penalty points") #finished a run so start again