have this very simple script in MATLAB. It draws a square in the middle of the screen and waits for the user response, provided by pressing the spacebar. Once given the response, the script presents the square again…and so on.
I want to integrate a touchscreen response, so that the user can respond touching the square on a touchscreen.
I know it possible to do it by using some function in MultiTouchDemo: Psychtoolbox-3 - MultiTouchDemo
But I really cannot integrate it in my script. Any advice?
This is my script:
try
screens = Screen('Screens');
whichscreen = max(screens);
[myscreen,rect]=Screen('OpenWindow',whichscreen);
DrawFormattedText(myscreen, 'PRESS ANY KEY TO PROCEED', 'center', 'center');
Screen('Flip', myscreen);
KbWait;
space = KbName('space');
ntrials = 6;
colorsequence = [1, 2, 2, 2, 1, 1];
rt = zeros(ntrials, 1);
stimulus_duration = zeros(ntrials, 1);
for i=1:ntrials
WaitSecs(1);
Screen('FrameOval', myscreen, 0, CenterRect([0, 0, 10, 10], rect));
onset_fixation = Screen('Flip', myscreen);
if colorsequence(i) == 1
stimuluscolor = [255, 0, 0];
else
stimuluscolor = [0, 255, 0];
end
Screen('FillRect', myscreen, stimuluscolor, CenterRect([0, 0, 50, 50], ...
rect));
random_delay = rand+0.5;
onset_stimulus = Screen('Flip', myscreen, onset_fixation + random_delay);
t0 = GetSecs;
[keyIsDown, secs, keyCode] = KbCheck;
while keyCode(space)==0 && (secs - onset_stimulus) < 2
[keyIsDown, secs, keyCode] = KbCheck;
end
rt(i) = secs - t0;
stimulus_offsettime = Screen('Flip', myscreen);
stimulus_duration(i) = stimulus_offsettime - t0;
end
screen('CloseAll');
catch
Screen('CloseAll')
rethrow(lasterror)
end
Thank you, best regards