Changes

Jump to navigation Jump to search
701 bytes removed ,  11:26, 16 November 2022
Line 103: Line 103:     
=== Python/PsychoPy ===
 
=== Python/PsychoPy ===
  −
Download this site-package to use the buttonbox: [https://pypi.python.org/pypi/RuSocSci rusocsci]
  −
  −
or use in windows command 'pip install --upgrade rusocsci'
  −
  −
'''Example using buttons from the buttonbox in Python:'''
  −
  −
<syntaxhighlight lang="python" line>
  −
#!/usr/bin/env python
  −
  −
# import the rusocsci.buttonbox module
  −
from rusocsci import buttonbox
  −
  −
# make a buttonbox
  −
bb = buttonbox.Buttonbox()
  −
  −
# wait for a single button press
  −
b = bb.waitButtons()
  −
  −
# print the button pressed
  −
print("b: {}".format(b))
  −
</syntaxhighlight>
  −
  −
'''Example using markers with the buttonbox in Python:'''
  −
  −
<syntaxhighlight lang="python" line>
  −
#!/usr/bin/env python
  −
  −
# import the rusocsci.buttonbox module
  −
from rusocsci import buttonbox
  −
  −
# make a buttonbox
  −
bb = buttonbox.Buttonbox()
  −
  −
# send a marker
  −
bb.sendMarker(val=100)    #This is your marker code, range code 1-255
  −
</syntaxhighlight>
      
<br/>'''Example using the Vertical Sync sensor in PsychoPy:'''
 
<br/>'''Example using the Vertical Sync sensor in PsychoPy:'''
Line 148: Line 111:  
# import psychopy and rusocsci
 
# import psychopy and rusocsci
 
from psychopy import core, visual  
 
from psychopy import core, visual  
from rusocsci import buttonbox
+
import serial
 +
import time
    
## Setup Section
 
## Setup Section
win = visual.Window(monitor="testMonitor")
+
win = visual.Window([400,400], fullscr=True, winType = "pyglet", monitor="testMonitor",color=(-1, -1, -1), units='cm',
bb = buttonbox.Buttonbox()
+
waitBlanking=True)
text = visual.TextStim(win, "Press a button on the buttonbox")
+
# connect to Vertical Sync sensor, find com port number
 +
ser = serial.Serial('com3', 115200, timeout=1.0)
 +
rect = visual.Rect(win, .15, .25, pos=(-1, 1),fillColor="white", units="norm")
 +
 
 +
# define treshold for OFF by sending a code
 +
ser.write(b'1')
    
## Experiment Section
 
## Experiment Section
 
# show text
 
# show text
text.draw()
+
rect.draw()
 
win.flip()
 
win.flip()
# wait for response
+
tok = time.perf_counter()
b = bb.waitButtons()
+
# wait for a sync square
 +
b = ser.read()
 +
tik = time.perf_counter()
 
# show response
 
# show response
text.setText("you pressed: {}".format(b))
+
print("your timing: {}".format(tik-tok))
text.draw()
  −
win.flip()
  −
core.wait(5)
      
## Cleanup Section
 
## Cleanup Section
 
core.quit()
 
core.quit()
 
</syntaxhighlight>
 
</syntaxhighlight>
  −
For more documentation click here: http://pythonhosted.org//RuSocSci/index.html
  −
<br>
  −
<br>
      
=== Matlab ===
 
=== Matlab ===

Navigation menu