Skip to content

Instantly share code, notes, and snippets.

@davelee212
Last active March 3, 2017 20:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davelee212/ac6394bda905cbdbe14314405112263f to your computer and use it in GitHub Desktop.
Save davelee212/ac6394bda905cbdbe14314405112263f to your computer and use it in GitHub Desktop.
# created as part of the Future Learn course on Physical Computing with Raspberry Pi
# prompts user to press a button when an LED lights and stores the reaction time. This is done
# 5 times, an average taken which is printed to screen then posted as a status update on Twitter
from gpiozero import LED
from gpiozero import Button
from time import sleep, time
from random import randint
import sys
from twython import Twython
# create a new application in twitter and put the info in below
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_KEY = ''
ACCESS_SECRET = ''
api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
red_led = LED(27)
btn = Button(4)
attempts = 5
total_reaction_time = 0
for i in range(attempts):
print ('')
print ('press the button when the LED goes on')
sleep(randint(1,10))
red_led.on()
start=time()
btn.wait_for_press()
red_led.off()
reaction_time = time() - start
print ('You took', reaction_time, 'seconds')
total_reaction_time = (total_reaction_time + reaction_time)
msg = 'According to my RPi, my average reaction time is ' + str(total_reaction_time/attempts) + ' seconds #picademy'
print msg
api.update_status(status=msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment