Dear experts,
I am using Matlab R2023a with PsychtoolboxVersion 3.0.19 - Flavor: beta - Corresponds to SVN Revision 13508 installed on a Surface Pro 6 Commercial Model 1796 i5 with Windows Windows 10 Pro.
I am not new to psychtoolbox, but I am new to record responses from touchscreens. I have searched for previous similar questions and tried to solve my problem by running the demos, but I am still not quite there. I would be very greatfull if you could help me.
I would like to create a sort of line bisection task, so I would like to display a line onscreen for unlimited time untill the patient touch it in the middle. However rather than just ask the patients to simply point (and touch the middle of the line) with one finger, I would like them to “grasp” the line, so by using two fingers, as if they are grasping a pen and measure the x and y of each of the two fingers (so that afterward I can measure the aperture of the fingers).
Below is part of the code that have the following two problems:
-
the line is diplayed onscreen, but then the screen is refreshed , so it turns black and then the line is disaplyes again. How can I avoid the screen from flashing black?
-
I would like the for loop across trials (different line lengths) to go on to the next trial soon after the patient has touched the screen (with the two fingers as described above), but at the moment it is going on only after keyboard press.
I copy part of the code below.
Resp=;
for t=1:length(pix_linelength)
% play sound
[soundData freq ] = audioread(‘ding.wav’);
PsychPortAudio(‘FillBuffer’, pahandle, soundData’);
PsychPortAudio(‘Start’, pahandle, 1,0);
WaitSecs(1)SetMouse(0, 0);
[x,y]=GetMouse;tic
% Get first touchscreen:
dev = min(GetTouchDeviceIndices(, 1));
info = GetTouchDeviceInfo(dev);
% Create and start touch queue for window and device:
TouchQueueCreate(w, dev);
TouchQueueStart(dev);% blobcol tracks active touch points - and dying ones:
blobcol = {};
buttonstate = 0;
blobmin = inf;% Main loop: Run until keypress:
while ~KbCheck
Screen(‘DrawLine’, w, [0 0 0], xmid-pix_linelength(t), ymid, xmid+pix_linelength(t), ymid, 10);
Screen(‘Flip’,w);
% Process all currently pending touch events:
while TouchEventAvail(dev)
% Process next touch event ‘evt’:
evt = TouchEventGet(dev, w);% Touch blob id - Unique in the session at least as % long as the finger stays on the screen: id = evt.Keycode; % Keep the id's low, so we have to iterate over less blobcol slots % to save computation time: if isinf(blobmin) blobmin = id - 1; end id = id - blobmin; if evt.Type == 0 % Not a touch point, but a button press or release on a % physical (or emulated) button associated with the touch device: buttonstate = evt.Pressed; continue; end if evt.Type == 1 % Not really a touch point, but movement of the % simulated mouse cursor, driven by the primary % touch-point: Screen('DrawDots', w, [evt.MappedX; evt.MappedY], baseSize, [1,1,1], [], 1, 1); continue; end if evt.Type == 2 % New touch point -> New blob! blobcol{id}.col = rand(3, 1); blobcol{id}.mul = 1.0; blobcol{id}.x = evt.MappedX; blobcol{id}.y = evt.MappedY; blobcol{id}.t = evt.Time; % Track time delta in msecs between touch point updates: blobcol{id}.dt = 0; end end
end
TouchQueueStop(dev);
TouchQueueRelease(dev);%coord two fingers
xfing1=blobcol{1}.x;
yfing1=blobcol{1}.y;xfing2=blobcol{2}.x;
yfing2=blobcol{2}.y;tr=toc;
Resp=[Resp;pix_linelength(t) yfing1 yfing1 yfing2 yfing2 ]
Screen(w,‘FillRect’,255);
Screen(‘Flip’,w);
WaitSecs(1)
end