FISCHER LAB
DEPARTMENT OF PSYCHOLOGICAL & BRAIN SCIENCES
JOHNS HOPKINS UNIVERSITY
125 AMES HALL
3400 NORTH CHARLES ST.
BALTIMORE, MD 21218

This line of code is used very frequently. This is because the cedrus has "pending" button presses. So if a participant presses a button by accident during the middle of your script when button presses are not being collected, this will "sit" in the cedrus box and will be displayed as the first button press the next time you do collect responses. Therefore, to be cautious, I use this line before and after collecting button presses. That way I can clear anything pending or lingering and collect only current responses. Also, both button presses and releases will/can be captured by the CedrusResponseBox functions. 

This will go at the beginning of the script.

  • Before connecting, this code closes anything cedrus related and establishes possible serial ports where the cedrus box could be connected.

  • To find the possible ports on a mac, go to terminal and type "ls /dev" copy and paste any port that you think could be the cedrus box. They will typically look like what I have below or something that starts with "/dev/tty.usbserial".

  • The try loop opens up information about your serial ports and tries to see if any of the occupied serial ports are the cedrus box and if one is it will create a handle for that port that will be used throughout the script

  • If none of the possibleCedrusPorts are actually the cedrus box, the screen will be closed and the error will be displayed

  • If you know that the cedrus is plugged into one of the ports you listed, close MATLAB unplug/reset the cedrus box, plug it back in and restart MATLAB

  • When running serial = instrhwinfo ('serial'), you may get this error: Undefined function 'instrhwinfo' for input arguments of type 'char'. You need to install the Instrument Control Toolbox for MATLAB using Mathworks, the same installation process as MATLAB.

Waiting for trigger

  • Flush any pending events

  • The while loop will keep going until the trigger is pressed; trigger should be defined above in the code (currently the fMRI trigger is the number 7 (it is button 6, but sent as 7 using XID) )

  • Inside of the while loop

  • 'WaitButtonPress' will wait until a cedrus button is pressed, when a button is pressed a struct called evt will be created

  • More about evt can be found on the CedruResponseBox documentation mentioned previously

  • if evt exists and the button is not the trigger, it will go through the while loop again

  • If evt exists and the button is the trigger, the cedrus and evt is cleared and the while loop is exited

Collecting button presses for a certain amount of time

This is example code that you will modify depending on how and when you collect responses

  • Flush events

  • the while loop will run for 10 seconds

    • Any button that is pressed will create evt

    • Time will be recorded

    • Things will be printed to a response file if all of these conditions are met

      • evt exists

      • a button was pressed not released (evt.action==0 for release and ==1 for press); 

      • the button pressed was the responseKey (which is defined here as button 2)

  • Remove evt.action==1 if you want to collect both button presses and releases

  • Remove evt.button==responseKey if you want all button presses to be recorded

    • BUT remember that the scanner will keep sending a pulse to your computer every TR (the trigger number will be sent as a button press) and you want to make sure this is NOT recorded so you would put evt.button~=trigger

Explain Cedrus Box Code