Example script
From SpinozaWiki
function Shocker_7T
% 24 reps with block duration 10 is 490 seconds total - 245 vols % 12 reps with block 10 is 250s
Reps = 24;%12 loop counter BlockDuration = 10;%void 10 AssertOpenGL;
% Here we call some default settings for setting up Psychtoolbox PsychDefaultSetup(2);
% Get the screen numbers. This gives us a number for each of the screens % attached to our computer. screens = Screen('Screens'); Screen('Preference', 'SkipSyncTests', 3);
% To draw we select the maximum of these numbers. So in a situation where we % have two screens attached to our monitor we will draw to the external % screen. screenNumber = min(screens); screenNumber = 1;
% Define black and white (white will be 1 and black 0). This is because % in general luminace values are defined between 0 and 1 with 255 steps in % between. All values in Psychtoolbox are defined between 0 and 1 white = WhiteIndex(screenNumber); black = BlackIndex(screenNumber); [width,height] = WindowSize(screenNumber); colorText = [0,255,0,155];
% Open an on screen window and color it black [window, windowRect] = PsychImaging('OpenWindow', screenNumber, black);
% Get the size of the on screen window in pixels % For help see: Screen WindowSize? [screenXpixels, screenYpixels] = Screen('WindowSize', window);
% Get the centre coordinate of the window in pixels % For help see: help RectCenter [xCenter, yCenter] = RectCenter(windowRect);
addpath('./MATLAB_port-IO'); % initialize access to the inpoutx64 low-level I/O driver config_io; % optional step: verify that the inpoutx64 driver was successfully initialized global cogent; if( cogent.io.status ~= 0 )
error('inp/outp installation failed');
end
address = hex2dec('AFE8'); %check address device manager, ports (COM &LP), LPT1 resources 1st entry orange
try
w=Screen('OpenWindow', screenNumber); Screen('FillRect', w,[0,0,0,0]); Screen('TextFont',w, 'Courier New'); Screen('TextSize',w, 80); Screen('TextStyle',w, 1); DrawFormattedText(w, '+', 'center', 'center',[0,255,0,155], [], 0); Screen('Flip',w); % add here the duration if overall length not right KbTriggerWait(KbName('t'),-3)%-3 makes sure the Forb box is caught getStart = GetSecs; pause(BlockDuration); %extra rest block at start for loopNums = 1:Reps BlockStart = GetSecs; Screen('FillRect', w, [0,0,0,0]); DrawFormattedText (w, '+', 'center', 'center', [0,255,0,155], [], 0); Screen('Flip',w); while GetSecs-BlockStart<BlockDuration %send trig to shock disp(GetSecs-BlockStart) byte = 0; outp(address,byte); byte = 255; outp(address,byte); pause(0.1) end BlockStart = GetSecs; Screen('FillRect', w, [0,0,0,0]); DrawFormattedText(w, '+', 'center', 'center', [0,255,0,155], [], 0); Screen('Flip',w); pause(BlockDuration); end catch % This "catch" section executes in case of an error in the "try" section % above. Importantly, it closes the onscreen window if it's open. Screen('CloseAll'); psychrethrow(psychlasterror); end
getEnd = GetSecs;
% Clear the screen. Screen('CloseAll'); sca;
disp(['Duration was :' num2str(getEnd-getStart)]);
end