ButtonBox: Difference between revisions

Jump to navigation Jump to search
improved examples
Line 410: Line 410:
|}
|}


== Psychopy Settings ==
== Buttonbox in Python and PsychoPy ==
Example using the buttonbox in Python:
<nowiki>
#!/usr/bin/env python


<nowiki>
# import the rusocsci.buttonbox module
#!/usr/bin/env python
from rusocsci import buttonbox import logging, time


from psychopy import core, visual, event from rusocsci import buttonbox import logging, time
# make a buttonbox
bb = buttonbox.Buttonbox()


##Setup Section
# wait for a single button press
#logging.getLogger().setLevel(logging.DEBUG) # use this for debug info
b = bb.waitButtons()  


win = visual.Window([400,300], monitor="testMonitor") bb = buttonbox.Buttonbox()
# print the button pressed
print("b: {}".format(b))
</nowiki>


##Experiment Section
Using the Buttonbox in PsychoPy
<nowiki>
#!/usr/bin/env python


b = bb.waitButtons(maxWait = 10.0, buttonList=['A']) print("b: {}".format(b))
# import psychopy and rusocsci
from psychopy import core, visual
from rusocsci import buttonbox


##Cleanup Section
## Setup Section
win = visual.Window(monitor="testMonitor")
bb = buttonbox.Buttonbox()
text = visual.TextStim(win, "Press a button on the buttonbox")


core.quit() The following script lights the LEDs under the buttons pressed.
## Experiment Section
# show text
text.draw()
win.flip()
# wait for response
b = bb.waitButtons()  
# show response
text.setText("you pressed: {}".format(b))
text.draw()
win.flip()
core.wait(5)


#!/usr/bin/env python
##Cleanup Section
#from __future__ import print_function
core.quit()
 
import logging, time, sys from rusocsci import buttonbox
 
##Setup Section
 
led = [False]*8
 
##Experiment Section
 
bb = buttonbox.Buttonbox() while True:
 
  buttons = bb.getButtons()
  if len(buttons):
  for c in buttons:
  if ord(c) >= ord('a') and ord(c) < ord('a')+8:
  led[ord(c) - ord('a')] = False
  elif ord(c) >= ord('A') and ord(c) < ord('A')+8:
  led[ord(c) - ord('A')] = True
  bb.setLeds(led)
  #print("buttons ({:3d}): {}{}".format(len(buttons), buttons, " "*50), end="\r")
  #sys.stdout.flush()</nowiki>


== Matlab Settings ==
== Matlab Settings ==