hi can you try this modified script and see what you get? The modifications are:
- stimulus changing color is not triggered by a random time - you trigger it by hitting the space bar. So essentially, it measures the time interval between two key presses instead of measuring your reaction time.
- there is a timer function that prints the elapsed time between stimulus change and keypress.
- i've added a second viz.Data object called dd and used that one for storing the time data from the second waitkeydown function.
I tested the code with an external stopwatch and seems accurate.
Code:
import viz
viz.go()
import vizinfo
info = vizinfo.add( 'This script uses precisely timed input recording to measure your reaction time.\nPress any key when the color changes to green.\nCan you get under .2 seconds?' )
#Add quad to screen
quad = viz.addTexQuad( viz.SCREEN , pos=(0.5,0.5,0) , scale=(4,4,4) )
#Display time on screen
timeDisplay = viz.addText( 'Time:', viz.SCREEN , pos=(0.1,0.2,0) )
import viztask
import time
starttime = time.time()
stopWatch = False
def TestReactionTime():
global starttime, stopWatch
#Data for getting values from wait conditions
d = viz.Data()
# dd = viz.Data()
while True:
#Set quad to red color
quad.color(viz.RED)
#Wait random amount of time
yield viztask.waitKeyDown(' ')
starttime = time.time()
stopWatch = True
#Set quad color to green
quad.color(viz.GREEN)
#Wait for next frame to be drawn to screen
yield viztask.waitDraw(d)
#Save display time
displayTime = d.time
#Wait for keyboard reaction
yield viztask.waitKeyDown(None,d)
#Calculate reaction time
reactionTime = d.time - displayTime
#Print and display time
print 'Reaction time:',reactionTime
timeDisplay.message( 'Time: %.5f' % (reactionTime) )
stopWatch = False
viztask.schedule( TestReactionTime() )
def showTime():
if stopWatch:
print time.time() - starttime
vizact.onupdate(-100, showTime)
Best,
Masaki