Advertisement
smathot

Untitled

Dec 15th, 2012
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. from openexp.keyboard import keyboard
  2.  
  3. # Inter-stimulus interval
  4. ITI = 50
  5.  
  6. # The number of cycles
  7. n_cycles = 10
  8.  
  9. # Set-up a keyboard object with a timeout equal to the interval
  10. # between the two stimuli
  11. my_keyboard = keyboard(exp, timeout=ITI)
  12.  
  13. # Copy the canvas from two sketchpads. You will show these sketchpads
  14. # here using inline_script, so in the experiment you probably want to
  15. # 'hide' them by setting the run-if statement to 'never'. Of course, you
  16. # can also canvases using inline script, instead of copying them from a
  17. # sketchpad.
  18. canvas_1 = self.copy_sketchpad('sketchpad_1')
  19. canvas_2 = self.copy_sketchpad('sketchpad_2')
  20.  
  21. # Start the response interval
  22. start_timestamp = self.time()
  23.  
  24. # We are going to keep a list of responses
  25. resp_list = []
  26.  
  27. # Go into a loop where the two canvases are shown in alternation
  28. for i in range(n_cycles):
  29.  
  30.     # Show the first canvas
  31.     t1 = canvas_1.show()
  32.    
  33.     # Use the get_key() function to sleep and monitor for keypresses
  34.     # at the same time.
  35.     resp, t2 = my_keyboard.get_key()
  36.     if resp != None:
  37.         # If a key was pressed, add it to the list of responses.
  38.         resp_list.append( (resp, t2) )
  39.         # And also sleep for the remaining time of the ITI
  40.         self.sleep(ITI - t2 + t1)
  41.        
  42.     # Same principle for the second canvas
  43.     t1 = canvas_2.show()
  44.     resp, t2 = my_keyboard.get_key()   
  45.     if resp != None:
  46.         resp_list.append( (resp, t2) )
  47.         self.sleep(ITI - t2 + t1)      
  48.    
  49. # If the response_list is empty, no response was given
  50. if len(resp_list) == 0:
  51.     response = 'timeout'
  52.     response_time = 0
  53.    
  54. # Otherwise get the first response from the list
  55. else:
  56.     resp, resp_timestamp = resp_list[0]
  57.     response = resp
  58.     response_time = start_timestamp - resp_timestamp
  59.  
  60. # Set the response variables!
  61. exp.set('response', resp)
  62. exp.set('response_time', response_time)
  63.  
  64. # To maintain feedback variables, see
  65. # <http://osdoc.cogsci.nl/usage/giving-feedback-to-participants/#inline-script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement