%% MEMOREYE - UNATTENDED % EYE TRACKING TEST - BASED ON THE UNATTENDED TASK % Bernhard Spitzer and Juan Linde Domingo, MARCH 2021, CN@RC %% Main diferences re previous version (00) % Reduced size of pings and objects % Correct delay between last ping and tests % Including 6 different colorsets for Pings % Background set to 128 %% Main diferences re previous version (00_1) % Practice added % Min delay between pings increased to 600ms (400ms before) %% Main diferences re previous version (00_5) % Practice and instructions done %% Only diferences re previous version (01) % Positions between cue and uncued items are uncorrelated % Gazebo images modified %% Only diferences re previous version (01_1) % Detecting whether participant are not looking to the fix cross and adding % this "null" trials to a final block. (no more than 48 trials) %% Only diferences re previous version (01_5) % Adding trials (50%) where after the test for the cued item we ask for the % uncued item % Only concrete task % Adding the possibility of not using pings % Instead of having a fixation cross, use a fixation DOT %% Differences compare to Memory_unateended_in_progress % Optimizing the off screen message %% Some changes in in progress 02 % (1) Remove pings (although we can leave an option to turn them on again) % - Here pings are important since we use their onset to check the gaze % during the delay period. One solution is not showing the object although % we keep the onset % (end) Update the output file % Change the spatial fix threshold (1.5) % Change the instructions % FB message closer to the center % No repetion of null triaLS (NON-FIXED) % Add a temporal threshold for non-fix messages % Push back the auditory cue after feedback 500ms %% Clean workspace and initialize the random number generator clear all; rand('state', sum(100*clock)); % Initialize the random number generator %% Adding PTB pathq ptb_path %% Prompt window prompt = {'Do you want to run a practice with instructions or the real task? (only practice=1; only real task=2)'}; defaults = {'2'}; answer = inputdlg(prompt, 'Practice or real experiment?', 1, defaults); [supra] = deal(answer{:}); supra = str2num(supra); % Open a Prompt Window and decoding the answer prompt = {'Task Version','Using the EEG-Lab PC? (0=no, 1=yes)','New Participant (0=no, 1=yes) ','Participant ID','Gender (M/F/Other)','Age','Righthanded? (0=no, 1=yes)','Stimuli subset (1 to 3)','Using Eye-tracking? (0=No;1=Yes)','Using EEG Triggers? (0=No;1=Yes)','Skip Sync Tests? (0=No;1=Yes)','First trial','Using pings (0=No;1=Yes)','Pings coloset (1 to 6)','Repeating non-fix trials? (0=No;1=Yes)','Total of trials','Visual Degrees Fix Cross Dev','Show Object','Show Dots'}; defaults = {mfilename, '1','1','XXX','X','99','1','2','1','0','0','1','0','1','0', '40' ,'3.5','0','1'}; answer = inputdlg(prompt, 'Experimental Setup Information', 1, defaults); [taskversion,lab,new_participant,subID, gender, age, righthanded, setofobjects,eyetracking,triggers_on, SkipSyncTests, firstrial, pingsareon, pingcolorset, repnonfixtrial, totalnunmtrials,visdegdis,showobject,showdot] = deal(answer{:}); age = str2num(age); righthanded = str2num(righthanded); eyetracking = str2num(eyetracking); original_eyetracking=eyetracking; triggers_on= str2num(triggers_on); original_triggers_on= triggers_on; SkipSyncTests =str2num(SkipSyncTests); setofobjects=str2num(setofobjects); pingcolorset = str2num(pingcolorset); firstrial=str2num(firstrial); new_participant=str2num(new_participant); lab=str2num(lab); repnonfixtrial=str2num(repnonfixtrial); totalnunmtrials=str2num(totalnunmtrials); pingsareon=str2num(pingsareon); %Ping on/off visdegdis=str2num(visdegdis); showobject=str2num(showobject); showdot=str2num(showdot); if supra==1 mxsq=1:3; elseif supra==2 if repnonfixtrial==1 mxsq=4:5; elseif repnonfixtrial==0 mxsq=4; end end if supra==1 subID=[subID 'pr'] end fixtrh=70000.5; %making sure the fixate! message will not be displayed gazeofftimelim=0.5; %time limits for the eyeoff % if new_participant==0 prompt = {'Participants could have a old EDF file. Choose the name for the new EDF file'}; defaults = {'1'}; answer = inputdlg(prompt, 'Experimental Setup Information', 1, defaults); [subID_neo] = deal(answer{:}); end %% Screen setup % Background color: cho ose a number from 0 (black) to 255 (white) backgroundColor = 128; clear screen if SkipSyncTests Screen('Preference', 'SkipSyncTests', 1) %%% IMPORTANT!! end whichScreen = max(Screen('Screens')); if lab [window1, rect] = Screen('Openwindow',whichScreen,backgroundColor,[],[],2); else [window1, rect] = Screen('Openwindow',whichScreen,backgroundColor,[0 0 800 600],[],2); end slack = Screen('GetFlipInterval', window1)/2; W=rect(RectRight); % screen width H=rect(RectBottom); % screen height % Get the centre coordinate of the window [xCenter, yCenter] = RectCenter(rect); Screen(window1,'FillRect',backgroundColor); HideCursor(window1); Screen('Flip', window1); %% Preparing Eyelink - Eye Tracking if eyetracking==1 dummymode=0; % STEP 2 % Provide Eyelink with details about the graphics environment % and perform some initializations. The information is returned % in a structure that also contains useful defaults % and control codes (e.g. tracker state bit and Eyelink key values). el=EyelinkInitDefaults(window1); % STEP 3 % Initialization of the connection with the Eyelink Gazetracker. % exit program if this fails. if ~EyelinkInit(dummymode) fprintf('Eyelink Init aborted.\n'); end [v vs]=Eyelink('GetTrackerVersion'); fprintf('Running experiment on a ''%s'' tracker.\n', vs ); % open file for recording data if new_participant edfFile=[subID '.edf']; Eyelink('Openfile', edfFile); else edfFile=[subID_neo '.edf']; Eyelink('Openfile', edfFile); end % STEP 4 % Do setup and calibrate the eye tracker EyelinkDoTrackerSetup(el); Eyelink('command', 'calibration_area_proportion = 0.45 0.45'); Eyelink('command', 'calibration_validation_proportion = 0.45 0.45'); % do a final check of calibration using driftcorrection % You have to hit esc before return. EyelinkDoDriftCorrection(el); % STEP 5 % Start recording eye position Eyelink('StartRecording'); % record a few samples before we actually start displaying WaitSecs(0.5); else edfFile=[]; end %% Checking keyboard, screens, audio, and adding others settings (e.g. timing) for the experiment settings_eyetracking_test; %% Open the serial port (Triggers) if triggers_on TB = IOPort('OpenSerialPort','COM4'); % in the lab x=4 else TB =[]; end %% Run the task % time of start of experiment and date trigger_beginning_end=245; ExpStart = GetSecs; today = date; barColor=[100 100 100] % Counter for interblock message accuracy accuracy_con= []; accuracy_abs= []; for maxiblock=mxsq; %3 first miniblocks of practices and then the task % PLAY SOUND (here trig is a sound signal) % 1) fill the buffer PsychPortAudio('FillBuffer', pahandle,(audtest)'); % 2) play it PsychPortAudio('Start', pahandle, repetitions, startCue); % 3) Stop when it's done playing PsychPortAudio('Stop', pahandle,1); if maxiblock==1 %first block of practice sequence=sequencepract1; practice=1; % eyetracking=0; triggers_on=0; imageFolder_in = 'instructions/one'; imgList_in = dir(fullfile(imageFolder_in,['*.jpg'])); imgList_in = {imgList_in(:).name}; showingslides(imgList_in,imageFolder_in,window1,W,H,backgroundColor,responseKeys) elseif maxiblock==2 sequence=sequencepract2; practice=1; % eyetracking=0; triggers_on=0; imageFolder_in = 'instructions/two'; imgList_in = dir(fullfile(imageFolder_in,['*.jpg'])); imgList_in = {imgList_in(:).name}; showingslides(imgList_in,imageFolder_in,window1,W,H,backgroundColor,responseKeys) elseif maxiblock==3 sequence=sequencepract3; practice=1; % eyetracking=0; triggers_on=0; imageFolder_in = 'instructions/three'; imgList_in = dir(fullfile(imageFolder_in,['*.jpg'])); imgList_in = {imgList_in(:).name}; showingslides(imgList_in,imageFolder_in,window1,W,H,backgroundColor,responseKeys) elseif maxiblock==4 %real task sequencenull=[] %Sequence of null trials sequence=sequence_real; practice=0; if original_eyetracking % Restore eyetracking on/off to original (to send triggers) eyetracking=1; else eyetracking=0; end if original_triggers_on % Restore triggers on/off to original triggers_on=1; else triggers_on=0; end press_trigger(trigger_beginning_end,TB,triggers_on); press_eyelink_trigger(trigger_beginning_end,eyetracking) % First Message Screen(window1, 'FillRect', backgroundColor); Screen('TextSize',window1,18); msg=['Welcome to the experiment']; DrawFormattedText(window1, msg, 'center', (H/4.5), textColor); DrawFormattedText(window1, '[Press the space bar to start]', 'center', (H/1.5), textColor); overviewTime = Screen('Flip',window1)-ExpStart; % first screen time Screen('TextSize',window1,40); % PLAY SOUND (here trig is a sound signal) % 1) fill the buffer PsychPortAudio('FillBuffer', pahandle,(audtest)'); % 2) play it PsychPortAudio('Start', pahandle, repetitions, startCue); % 3) Stop when it's done playing PsychPortAudio('Stop', pahandle,1); % Wait for subject to press spacebar while 1 [keyIsDown,secs,keyCode] = KbCheck; if keyCode(KbName('space'))==1 break end end elseif maxiblock==5 %repeating null trials (fix point) %randomize the sequencenull sequencenull=sequencenull(randperm(size(sequencenull,1)),:) sequencenull(:,10)=nblocks+1; %and put the same number for the blocks if size(sequencenull,1)>48 %Maximum trials to repeat sequencenull=sequencenull(1:48,:) end sequence=sequencenull; practice=0; firstrial=1; if original_eyetracking % Restore eyetracking on/off to original (to send triggers) eyetracking=1; else eyetracking=0; end if original_triggers_on % Restore triggers on/off to original triggers_on=1; else triggers_on=0; end press_trigger(trigger_beginning_end,TB,triggers_on); press_eyelink_trigger(trigger_beginning_end,eyetracking) % First Message Screen(window1, 'FillRect', backgroundColor); Screen('TextSize',window1,18); msg=['Almost done. We will repeat some trials where your gaze was not in the center']; DrawFormattedText(window1, msg, 'center', (H/4.5), textColor); DrawFormattedText(window1, '[Press the space bar to start]', 'center', (H/1.5), textColor); overviewTime = Screen('Flip',window1)-ExpStart; % first screen time Screen('TextSize',window1,40); % PLAY SOUND (here trig is a sound signal) % 1) fill the buffer PsychPortAudio('FillBuffer', pahandle,(audtest)'); % 2) play it PsychPortAudio('Start', pahandle, repetitions, startCue); % 3) Stop when it's done playing PsychPortAudio('Stop', pahandle,1); % Wait for subject to press spacebar while 1 [keyIsDown,secs,keyCode] = KbCheck; if keyCode(KbName('space'))==1 break end end end for trial=firstrial:totalnunmtrials% size(sequence,1) % Parameters for each trial (clarification) % In Sequence: % Column 1 = Object 1 % Column 2 = Object 2 % Column 3 = Rotation Object 1 % Column 4 = Rotarion Object 2 % Column 5 = Target: 1 or 2 % Column 6 = Target Object (id) % Column 7 = Type of task (1= concrete/perceptual; 2=continuous/abstract) % Column 8 = Object memory test % Column 9 = Rotation Object memory test % Column 10 = Block number % Column 11 = Rotation target % Column 12 = Testing uncued (True / False) % Column 13 = Object memory test 2 % Column 14 = Rotation Object memory test 2 % Column 15 = Rotation UNCUED object_1_id=sequence(trial,1); object_2_id=sequence(trial,2); object_1_rot=sequence(trial,3); object_2_rot=sequence(trial,4); cue=sequence(trial,5); type_of_task=sequence(trial,7); object_test_id=sequence(trial,8); object_test_rot=sequence(trial,9); block=sequence(trial,10); all_rotation = unique(sequence_real(:,3)); object_cue_id=sequence(trial,6); object_cue_rot=sequence(trial,11); object_uncued_id=sequence(trial,13); object_uncued_rot=sequence(trial,15); pingfixated=zeros(1,8); pingfixated_2=zeros(1,8); testinguncued=0; object_test_id_uncued=sequence(trial,13); object_test_rot_uncued=sequence(trial,14); if trial0); trigger_object_abstract=object_test_id+200; trigger_object_concrete_uncued= 222+(degdiff>0); trigger_object_abstract_uncued=object_test_id+210; trigger_ping=230; trigger_odd_ping=231; trigger_ping_2=232; trigger_odd_ping_2=233; trigger_left_key=241; trigger_right_key=242; trigger_up_key=243; trigger_feedback=244; trigger_feedback_uncued=245; trigger_beginning_end=246; %% Pre-load stimuli and other settings bth=254% treshold to subtitute for background sc_o=(10000/W)*1.4; %Object 1 file_object_1 = imgList{object_1_id}; img_object_1 = imread(fullfile(imageFolder ,file_object_1)); img_object_1((img_object_1>=bth))=backgroundColor; %REMOVING BACKGROUND FOR EACH IMAGE objectDisplay_1 = Screen('MakeTexture', window1, img_object_1); % Calculate image position (center of the screen) OBJECT 1 imageSize_o1 = size(img_object_1)/sc_o; pos_o1 = [(W-imageSize_o1(2))/2 (H-imageSize_o1(1))/2 (W+imageSize_o1(2))/2 (H+imageSize_o1(1))/2]; %Object 2 file_object_2 = imgList{object_2_id}; img_object_2 = imread(fullfile(imageFolder ,file_object_2)); img_object_2((img_object_2>=bth))=backgroundColor; %REMOVING BACKGROUND FOR EACH IMAGE objectDisplay_2 = Screen('MakeTexture', window1, img_object_2); % Calculate image position (center of the screen) OBJECT 2 imageSize_o2 = size(img_object_2)/sc_o; pos_o2 = [(W-imageSize_o2(2))/2 (H-imageSize_o2(1))/2 (W+imageSize_o2(2))/2 (H+imageSize_o2(1))/2]; %Object Memory Test (we will use a difference object for the %abstract task) if type_of_task==2 file_object_t = imgList_test{object_test_id}; img_object_t = imread(fullfile(imageFolder_test ,file_object_t)); img_object_t((img_object_t>=bth))=backgroundColor; %REMOVING BACKGROUND FOR EACH IMAGE objectDisplay_test = Screen('MakeTexture', window1, img_object_t); else file_object_t = imgList{object_test_id}; img_object_t = imread(fullfile(imageFolder,file_object_t)); img_object_t((img_object_t>=bth) )=backgroundColor ; %REMOVING BACKGROUND FOR EACH IMAGE objectDisplay_test = Screen('MakeTexture', window1, img_object_t); proof=img_object_t;proof(:,:,1)=proof(:,:,1)./1.5;proof(:,:,3)=proof(:,:,3)./1.5; proof((img_object_t==backgroundColor) )=backgroundColor ; %REMOVING BACKGROUND FOR EACH IMAGE objectDisplay_test_green = Screen('MakeTexture', window1, proof); proof=img_object_t;proof(:,:,2)=proof(:,:,2)./1.5;proof(:,:,3)=proof(:,:,3)./1.5; proof((img_object_t==backgroundColor))=backgroundColor ; %REMOVING BACKGROUND FOR EACH IMAGE objectDisplay_test_red = Screen('MakeTexture', window1, proof); file_object_t_uncued = imgList{object_test_id_uncued}; img_object_t_uncued = imread(fullfile(imageFolder,file_object_t_uncued)); img_object_t_uncued((img_object_t_uncued>=bth) )=backgroundColor ; %REMOVING BACKGROUND FOR EACH IMAGE objectDisplay_test_uncued = Screen('MakeTexture', window1, img_object_t_uncued); end % Calculate image position (center of the screen) OBJECT TEST imageSize_ot = size(img_object_t)/sc_o; pos_ot = [(W-imageSize_ot(2))/2 (H-imageSize_ot(1))/2 (W+imageSize_ot(2))/2 (H+imageSize_ot(1))/2]; %Setting the position of the oddball ping %Calcularing the time gap between pings pausvec=pingT(npings,nodd,delth,pilth,minipi,maxsend,minstart) odvec=[zeros(1,npings-nodd) ones(1,nodd)]; % vector defining which ping is an oddball oddpingpos=odvec(randperm(npings)); %Calcularing the time gap between pings for the SECOND delay pausvec_2=pingT(npings_2,nodd_2,delth_2,pilth_2,minipi_2,maxsend_2,minstart_2) odvec_2=[zeros(1,npings_2-nodd_2) ones(1,nodd_2)]; % vector defining which ping is an oddball oddpingpos_2=odvec_2(randperm(npings_2)); %% Showing OBJECT 1 objectodisplay=objectDisplay_1; rottodisplay=object_1_rot; positiontodisplay=pos_o1; Onset_object_1=NaN; object_1_fixated=NaN; OnsetResp=0; rt_catch = 0; resp_text = 0; resp_catch = 'No_Response'; %Just in case we don't have response if showobject % Screen priority Priority(MaxPriority(window1)); Priority(2); if eyetracking==1 % Before 'Flip' check whether the eyes are well fixated to change the trigger id eyesin=0; eyesout=0; eyes_were_out=0; too=[]; %if eyes are not fixated, the trial will not start while eyesin==0 too(1) = gazein(W,H,fixtrh,gazeofftimelim,0); too(1) if too(1)==1 eyesin=1; elseif too(1)==0 eyes_were_out=1; end end end %If eyes were not fixated before the trial start (time lenght %defined by fixationDuration) if eyetracking==1 if eyes_were_out drawDot(window1,W,H,barColor); tFixation = Screen('Flip', window1); Screen(window1, 'FillRect', backgroundColor); Screen('Flip', window1, tFixation + (fixationDuration - slack),0) %Adding between 0 and 0.5 second randomly to the minimum for the fixation duration Screen('TextSize',window1,40); DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]); end end % Show fixation cross drawDot(window1,W,H,barColor); tFixation = Screen('Flip', window1); Screen(window1, 'FillRect', backgroundColor); Screen('Flip', window1, tFixation + (fixationDuration + (rand(1)/2))- slack,0) %Adding between 0 and 0.5 second randomly to the minimum for the fixation duration % Show Object 1 Screen('DrawTexture', window1, objectodisplay, [], positiontodisplay,rottodisplay); drawDot(window1,W,H,barColor); %Fixcross on top object_1_fixated=0; %eye centered if eyetracking==1 % Before 'Flip' check whether the eyes are well fixated to change the trigger id object_1_fixated = gazeoff(W,H,fixtrh,gazeofftimelim,0); end startTime = Screen('Flip', window1); % Start of trial Onset_object_1 = startTime-ExpStart; %Onset tdel=press_trigger(trigger_object_1,TB,triggers_on); press_eyelink_trigger(trigger_object_1,eyetracking) startout=[]; while (GetSecs - startTime) < objectTimeout - tdel - slack [keyIsDown,secs,keyCode] = KbCheck; % ESC key quits the experiment if keyCode(KbName('Q')) == 1 endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile) end respTime = GetSecs; pressedKeys = find(keyCode); % Check for response keys if ~isempty(pressedKeys) for i = 1:length(responseKeys) if KbName(responseKeys{i}) == pressedKeys(1) break end end end if eyetracking==1 nnf(1) = gazeoff(W,H,fixtrh,gazeofftimelim,0); if nnf(1)==0 continue end startout=[startout GetSecs]; if startout(end)-startout(1)>gazeofftimelim %pingfixated(1) %Eyes not fixated! object_1_fixated=1; end end end % Empty screen between object offset and next fix cross % Screen priority Priority(MaxPriority(window1)); Priority(2); Screen(window1, 'FillRect', backgroundColor); Screen('Flip', window1 ) while (GetSecs - startTime) < postobjectTimeout1 - slack % ESC key quits the experiment if keyCode(KbName('Q')) == 1 endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile) end [keyIsDown,secs,keyCode] = KbCheck; respTime = GetSecs; pressedKeys = find(keyCode); % Check for response keys if ~isempty(pressedKeys) for i = 1:length(responseKeys) if KbName(responseKeys{i}) == pressedKeys(1) resp_catch = responseKeys{i}; rt_catch = respTime - startTime; OnsetResp = GetSecs - ExpStart; break end end end end end %% Showing OBJECT 2 objectodisplay=objectDisplay_2; rottodisplay=object_2_rot; positiontodisplay=pos_o2; Onset_object_2=NaN object_2_fixated=NaN; OnsetResp=0; rt_catch = 0; resp_text = 0; resp_catch = 'No_Response'; %Just in case we don't have response if showobject % Screen priority Priority(MaxPriority(window1)); Priority(2); % Show fixation cross Screen(window1, 'FillRect', backgroundColor); drawDot(window1,W,H,barColor); % %If eyes were not fixated in object 1 % if object_1_fixated % Screen('TextSize',window1,40); % DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]); % end tFixation = Screen('Flip', window1); Screen('Flip', window1, tFixation + (fixationDuration)- slack,0) % Show Object 2 Screen('DrawTexture', window1, objectodisplay, [], positiontodisplay,rottodisplay); drawDot(window1,W,H,barColor); %Fixcross on top object_2_fixated=0; %eye centered if eyetracking==1 % Before 'Flip' check whether the eyes are well fixated to change the trigger id object_2_fixated = gazeoff(W,H,fixtrh,gazeofftimelim,0); end startTime = Screen('Flip', window1); % Start of trial Onset_object_2 = startTime-ExpStart; %Onset tdel=press_trigger(trigger_object_2,TB,triggers_on); press_eyelink_trigger(trigger_object_2,eyetracking) startout=[]; while (GetSecs - startTime)< objectTimeout - tdel - slack [keyIsDown,secs,keyCode] = KbCheck; % ESC key quits the experiment if keyCode(KbName('Q')) == 1 endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile) end respTime = GetSecs; pressedKeys = find(keyCode); % Check for response keys if ~isempty(pressedKeys) for i = 1:length(responseKeys) if KbName(responseKeys{i}) == pressedKeys(1) break end end end if eyetracking==1 nnf(1) = gazeoff(W,H,fixtrh,gazeofftimelim,0); if nnf(1)==0 continue end startout=[startout GetSecs]; if startout(end)-startout(1)>gazeofftimelim %pingfixated(1) %Eyes not fixated! object_2_fixated=1; end end end % Empty screen between object offset and next fix cross % Screen priority Priority(MaxPriority(window1)); Priority(2); Screen(window1, 'FillRect', backgroundColor); drawDot(window1,W,H,barColor); %Fixcross on top %If eyes were not fixated in object 2 if object_2_fixated Screen('TextSize',window1,40); DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]); end startTime = Screen('Flip', window1 ) while (GetSecs - startTime)< postobjectTimeout2 - slack % ESC key quits the experiment if keyCode(KbName('Q')) == 1 endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile) end [keyIsDown,secs,keyCode] = KbCheck; respTime = GetSecs; pressedKeys = find(keyCode); % Check for response keys if ~isempty(pressedKeys) for i = 1:length(responseKeys) if KbName(responseKeys{i}) == pressedKeys(1) resp_catch = responseKeys{i}; rt_catch = respTime - startTime; OnsetResp = GetSecs - ExpStart; break end end end end end %% showing fix cross in different positions ranfixcrosdev=fixcrosdev(randperm(size(fixcrosdev,1)),:); trigger_fixcrosdev=200+ranfixcrosdev(:,3); if showdot Priority(MaxPriority(window1)); Priority(2); for cm = 1:size(fixcrosdev,1); PW=ranfixcrosdev(cm,1); PH=ranfixcrosdev(cm,2); % trigger_fixcrosdev(cm)=200+ranfixcrosdev(cm,3); % Screen priority % Show fixation cross drawDotaround(window1,W,H,PW,PH,barColor); tFixation = Screen('Flip', window1); press_eyelink_trigger(trigger_fixcrosdev(cm),eyetracking) Screen(window1, 'FillRect', backgroundColor); Screen('Flip', window1, tFixation + (fixationDuration)- slack,0) %Adding between 0 and 0.5 second randomly to the minimum for the fixation duration end end %% Showing retro cue (sounds) Onset_retrocue=NaN; % % % % Screen priority % % % Priority(MaxPriority(window1)); % % % Priority(2); % % % % % % % Show fixation cross % % % % % % drawDot(window1,W,H,barColor); % % % startTime = Screen('Flip', window1); % % % Onset_retrocue = startTime-ExpStart; %Onset % % % press_trigger(trigger_retrocue,TB,triggers_on); % % % press_eyelink_trigger(trigger_retrocue,eyetracking) % % % % % % % % % % Show retro cue (visual) % % % % % % % % % % % % % Screen('Flip', window1, tFixation + (fixationDuration + rand(1))- slack,0) %Adding between 0 and 1 second randomly to the minimum for the fixation duration % % % % % % % % % % % % % % % % % % % % % Screen('TextSize',window1,60); % % % % % % % DrawFormattedText(window1, num2str(cue), 'center', 'center', [255 255 255]); % % % % % % % % % % % % % % startTimePing = Screen('Flip',window1)-ExpStart; % first screen time % % % % % % % Presenting retro cue with audio % % % % % % % PLAY SOUND (here trig is a sound signal) % % % % 1) fill the buffer % % % PsychPortAudio('FillBuffer', pahandle,(audcue{cue})'); % % % % 2) play it % % % PsychPortAudio('Start', pahandle, repetitions, startCue); % % % % % % % 3) Stop when it's done playing % % % PsychPortAudio('Stop', pahandle,1); % % % % % % % % % % WaitSecs(audiogap) %% Showing the Pings (if the option is on) if pingsareon % Draw the pings if the variable pingsareon is 1 for pings=1:size(oddpingpos,2) %How many pings %In this example the oddball will be a different color for the %text if oddpingpos(pings)==1 rectColor_s=rectColor_odd; trigger_ping_selected=trigger_odd_ping else rectColor_s=rectColor; trigger_ping_selected=trigger_ping end % Screen priority Priority(MaxPriority(window1)); Priority(2); % Show fixation cross Screen(window1, 'FillRect', backgroundColor); drawDot(window1,W,H,barColor); tFixation = Screen('Flip', window1); %Duration of fix cross is based on "pausvec" Screen('Flip', window1, tFixation + (pausvec(pings)/1000)- slack,0) %Adding time to the minimum for the fixation duration Screen('FillOval', window1, rectColor_s{1}, centeredRect1, maxDiameter1); Screen('FillOval', window1, rectColor_s{2}, centeredRect2, maxDiameter2); Screen('FillOval', window1, rectColor_s{3}, centeredRect3, maxDiameter3); Screen('FillOval', window1, rectColor_s{4}, centeredRect4, maxDiameter4); Screen('FillOval', window1, rectColor_s{5}, centeredRect5, maxDiameter5); drawDot(window1,W,H,barColor); %Fixcross on top pingfixated(pings)=0; %eye centered if eyetracking==1 % Before 'Flip' check whether the eyes are well fixated to change the trigger id pingfixated(pings) = gazeoff(W,H,fixtrh,gazeofftimelim,0); if pingfixated(pings) Screen('TextSize',window1,40); DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]); end end % Flip to the screen startTime = Screen('Flip', window1); tdel=press_trigger(trigger_ping_selected,TB,triggers_on); press_eyelink_trigger(trigger_ping_selected,eyetracking) Onset_ping(pings) = startTime-ExpStart; startout=[]; while GetSecs - startTime < ((pilth/1000)-tdel - slack) if eyetracking==1 nnf(1) = gazeoff(W,H,fixtrh,gazeofftimelim,0); if nnf(1)==0 continue end startout=[startout GetSecs]; if startout(end)-startout(1)>gazeofftimelim %pingfixated(1) %Eyes not fixated! pingfixated(pings)=1; Screen('TextSize',window1,40); DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]); startTimeFiXM =Screen('Flip', window1) end end end end else %if PINGS are off startout=[]; % % Screen priority % Priority(MaxPriority(window1)); % Priority(2); % % % Show fixation cross % % Screen(window1, 'FillRect', backgroundColor); % drawDot(window1,W,H,barColor); % startTimeA = Screen('Flip', window1); % % % while GetSecs - startTimeA < ((delth/1000)-(pausvec(end)/1000)- slack) % During the time of the delay period % % if eyetracking==1 % % nnf(1) = gazeoff(W,H,fixtrh,gazeofftimelim,0); % if nnf(1)==0 % continue % % end % % startout=[startout GetSecs]; % % if startout(end)-startout(1)>gazeofftimelim %pingfixated(1) %Eyes not fixated! % pingfixated(1)=1; % Screen('TextSize',window1,40); % DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]); % startTimeFiXM =Screen('Flip', window1) % % end % % end % % end end %% Showing OBJECTs for Memory test (Discrete/perceptual task) if type_of_task==1 acc_trial_concrete=NaN; OnsetResp=0; rt_resp_concrete = 0; resp_text = 0; resp = 'No_Response'; %Just in case we don't have response rotationAngle_test=object_test_rot; finalrot_concrete=NaN; % % % % Screen priority % % % Priority(MaxPriority(window1)); % % % Priority(2); % % % % % % % Show fixation cross % % % % % % drawDot(window1,W,H,barColor); % % % tFixation = Screen('Flip', window1); % % % % % % Screen(window1, 'FillRect', backgroundColor); % % % Screen('Flip', window1, tFixation + (pausvec(end)/1000)- slack,0) %Adding between 0 and 1 second randomly to the minimum for the fixation duration % % % % % % % Show Object % % % % % % Screen('TextSize',window1,18); % % % DrawFormattedText(window1, 'Press <- or -> to CHOOSE the right direction', 'center', (H/4.5), textColor); % % % Screen('DrawTexture', window1, objectDisplay_test, [], pos_ot,rotationAngle_test); % % % startTime_test = Screen('Flip', window1); % Start of trial % % % press_trigger(trigger_object_concrete,TB,triggers_on); % % % press_eyelink_trigger(trigger_object_concrete,eyetracking) % % % % % % Onset_object_pt = startTime-ExpStart; %Onset % % % Onset_test = startTime_test-ExpStart; %Onset % % % % % % responsetimeout=0; % % % % % % stop=1; % % % % % % % % % while stop % GetSecs - startTime < objectTimeout % % % % % % [keyIsDown,secs,keyCode] = KbCheck; % % % % ESC key quits the experiment % % % if keyCode(KbName('Q')) == 1 % % % % % % endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile) % % % % % % end % % % respTime = GetSecs; % % % pressedKeys = find(keyCode); % % % % % % % Check for response keys % % % if ~isempty(pressedKeys) % % % for i = 2:3 % % % if KbName(responseKeys{i}) == pressedKeys(1) % % % resp = responseKeys{i}; % % % rt_resp_concrete= respTime - startTime_test; % % % OnsetResp = GetSecs - ExpStart; % % % % % % if keyCode(KbName('RightArrow')) == 1 % % % press_trigger(trigger_right_key,TB,triggers_on); % % % press_eyelink_trigger(trigger_right_key,eyetracking) % % % % % % elseif keyCode(KbName('LeftArrow')) == 1 % % % press_trigger(trigger_left_key,TB,triggers_on); % % % press_eyelink_trigger(trigger_left_key,eyetracking) % % % % % % end % % % % % % break % % % % % % end % % % end % % % end % % % % % % if rt_resp_concrete > 0 % % % stop=0; % % % break % % % elseif (GetSecs - startTime_test > concreteTimeout - slack) % % % stop=0; % % % responsetimeout=1; % % % end % % % end % % % % % % % Showing the move % % % % % % if keyCode(KbName('RightArrow')) == 1 % % % % % % Screen('TextSize',window1,18); % % % DrawFormattedText(window1, 'Press <- or -> to CHOOSE the right direction', 'center', (H/4.5), textColor); % % % Screen('DrawTexture', window1, objectDisplay_test, [], pos_ot,rotationAngle_test+distrot/contestdif); % % % startTime = Screen('Flip', window1); % Start of trial % % % Onset_object_pt = startTime-ExpStart; %Onset % % % % % % finalrot_concrete=rotationAngle_test+distrot/contestdif; % % % % % % end % % % % % % if keyCode(KbName('LeftArrow')) == 1 % % % % % % Screen('TextSize',window1,18); % % % DrawFormattedText(window1, 'Press <- or -> to CHOOSE the right direction', 'center', (H/4.5), textColor); % % % Screen('DrawTexture', window1, objectDisplay_test, [], pos_ot,rotationAngle_test-distrot/contestdif); % % % startTime = Screen('Flip', window1); % Start of trial % % % Onset_object_pt = startTime-ExpStart; %Onset % % % % % % finalrot_concrete=rotationAngle_test-distrot/contestdif; % % % % % % end % % % % % % WaitSecs(fbrespcon) % % % % % % % % % %% Feedback Concrete using images % % % % % % %Obtaining right answer % % % % % % if responsetimeout % % % fb_message= (['Try to respond faster']) % % % acc_trial_concrete=2; % % % textColor_fb=[255 0 0] % % % % % % else % % % degdiff=angdiff(deg2rad(object_cue_rot),deg2rad(object_test_rot)); % angular difference % % % degdiff=rad2deg(degdiff) % % % if degdiff<0 % % % corr_r='R' % % % else % % % corr_r='L' % % % end % % % % % % %Preparing FB message % % % if resp(1)==corr_r % % % fb_message = 'correct' % % % accuracy_con=[accuracy_con 1]; % % % acc_trial_concrete=1; % % % % % % objectDisplay_fb=objectDisplay_test_green; % % % textColor_fb=[0 255 100] % % % % % % else % % % fb_message = 'incorrect' % % % accuracy_con=[accuracy_con 0]; % % % acc_trial_concrete=0; % % % objectDisplay_fb=objectDisplay_test_red; % % % textColor_fb=[255 0 0] % % % % % % % % % end % % % % % % end % % % % % % Screen('TextSize',window1,20); % % % DrawFormattedText(window1, fb_message, 'center', (H/4.5), textColor_fb); % % % Screen('DrawTexture', window1, objectDisplay_test,[], pos_ot,object_cue_rot,1,0.9); % % % % % % startTime=Screen('Flip', window1); % Start of feedback % % % Onset_feedback = startTime-ExpStart; %Onset % % % press_trigger(trigger_feedback,TB,triggers_on); % % % press_eyelink_trigger(trigger_feedback,eyetracking) % % % % % % % % % % % % WaitSecs(fbtimeoutcon- slack) end %% Showing OBJECTs for Memory test (Abstract task) %% Giving feedback (B updated to circular) (Continuous task) %% At the end of the cued item test, we will either: % (i) present an "Thank you" audio, to finish the trial % (ii) cue the uncued item % % % if testinguncued % % % second_aud=(audcue{uncue})'; % % % trigger_ready_2=trigger_retrocue_2; % If we test the uncued, the trigger will be retrocued_2 % % % else % % % second_aud=(audthanks{1})'; % % % trigger_ready_2= trigger_thanks; % If we DO NOT test the uncued, the trigger will be trigger_thanks (thanks messages after testing the cued item) % % % % % % end % % % % % % % % % % Screen priority % % % Priority(MaxPriority(window1)); % % % Priority(2); % % % % % % % Show fixation cross % % % % % % drawDot(window1,W,H,barColor); % % % startTime = Screen('Flip', window1); % % % Onset_retrocue_2 = startTime-ExpStart; %Onset % % % press_trigger(trigger_ready_2,TB,triggers_on); % % % press_eyelink_trigger(trigger_ready_2,eyetracking) % % % % % % % WaitSecs(fbaudiogap) % % % % % % % % % % Presenting retro cue with audio % % % % % % % PLAY SOUND (here trig is a sound signal) % % % % 1) fill the buffer % % % PsychPortAudio('FillBuffer', pahandle,second_aud); % % % % 2) play it % % % PsychPortAudio('Start', pahandle, repetitions, startCue); % % % % % % % 3) Stop when it's done playing % % % PsychPortAudio('Stop', pahandle,1); %% If there is a TEST for the UNCUED item %% Updating outputfile %Info to include (related to trial) pingsareon; %Ping on/off block; testinguncued; object_1_id; object_2_id; file_object_1; %name of the file file_object_2; object_1_rot; object_2_rot; object_1_fixated; object_2_fixated; cue; uncue; object_cue_id; object_cue_rot; object_uncued_id; object_uncued_rot; type_of_task=sequence(trial,7); %1=concrete and 2=abstract total_of_pings= length(oddpingpos); %sequence of pings (1== oddball) position_odd_pings= find(oddpingpos==1); pingfixated; object_test_id; object_test_rot; total_of_pings_2= length(oddpingpos_2); %sequence of pings (1== oddball) position_odd_pings_2= find(oddpingpos_2==1); pingfixated_2; object_test_id_uncued; object_test_rot_uncued; %Info to include (related to partipants' response) if type_of_task==2 trigger_object_concrete=NaN; rt_resp_concrete =NaN; acc_trial_concrete =NaN; %0== Incorrect, 1== Correct; 2== No response/too slow) finalrot_concrete =NaN;% final rotation for concrete task rt_resp_concrete_uncued elseif type_of_task==1 trigger_object_abstract=NaN; rt_resp_abstract_ini=NaN rt_resp_abstract =NaN; acc_trial_abstract =NaN; % Percentage; NaN == No response/too slow) rotationAngle_test =NaN; % final rotation for abstract task end if testinguncued ==0 resp_uncued = NaN; trigger_object_concrete_uncued = NaN; rt_resp_concrete_uncued = NaN; acc_trial_concrete_uncued = NaN; %0== Incorrect, 1== Correct; 2== No response/too slow) finalrot_concrete_uncued = NaN;% final rotation for concrete task Onset_test_uncued= NaN; OnsetResp_uncued = NaN; Onset_feedback_uncued=NaN; Onset_thanks_uncued = NaN; end % Time Onsets - A temporal list Onset_object_1; %Object 1 Onset_object_2;%Object 2 Onset_retrocue;%Retro cue Onset_taskcue=NaN;%Task cue. Nothing here in this task. Onset_ping; %List the ping onset Onset_test=NaN;%Test on screen OnsetResp=NaN; %Response onset for the cued test Onset_feedback=NaN;%Feedback Onset_retrocue_2=NaN; % Important: this can be retrocue for uncued or a thank message Onset_ping_2=NaN; %List the ping onset (second delay) Onset_test_uncued=NaN; %Test for the uncued on screen (only if tested) OnsetResp_uncued=NaN; %Response onset for the uncued test (only if tested) Onset_feedback_uncued=NaN; %FB for the uncued on screen (only if tested) Onset_thanks_uncued=NaN; % For the bonus system if maxiblock==4 bon_acc_concrete(trial)=acc_trial_concrete; bon_acc_abstract(trial)=acc_trial_abstract; end % Save the null trials for a if nansum([pingfixated(:); pingfixated_2(:); object_1_fixated; object_2_fixated])>0&&repnonfixtrial if practice==0 sequencenull=[sequencenull; sequence(trial,:)] if size(sequencenull,1)>48 % fixtrh=35; end end end if maxiblock==5 blocknulrep=1; else blocknulrep=0; end %% Saving data to outputfile % Set up the output file (this output is for info related with the % presention of room-object association and word tasks) % resultsFolder = 'outputfiles'; % outputfile = fopen([resultsFolder '/resultfile_' num2str(subID) '.txt'],'a'); % fprintf(outputfile, 'task_version\t date\t subID\t sub_gender\t sub_age\t block_number\t trial\t object_1_name\t object_1_id\t object_1_rot\t object_2_name\t object_2_ID\t object_2_rot\t retro_cue\t object_cue_id\t object_cue_rot\t type_of_task\t type_of_ings\t position_odd_pings\t object_test_name\t object_test_id\t object_test_rot\t rt_resp_concrete\t acc_trial_concrete\t final_rot_concrete\t rt_resp_abstract_first_key\t rt_resp_abstract\t acc_trial_abstract\t final_rot_abstract\t onset_object_1\t onset_object_2\t onset_retrocue\t onset_taskcue\t onset_test\t onset_feedback\t onset_ping_1\t onset_ping_2\t onset_ping_3\t onset_ping_4\t onset_ping_5\t onset_ping_6\t onset_ping_7\t onset_ping_8\t onset_ping_9\t onset_ping_10\t trigger_object_1\t trigger_object_2\t trigger_retrocue_1\t trigger_taskcue\t trigger_object_concrete\t trigger_object_abstract\t colorset_pins\n'); if pingsareon %if we are using pings the outputfile will be more detailed % Save results to file fprintf(outputfile, '%s\t %s\t %s\t %s\t %d\t %d\t %d\t %s\t %d\t %d\t %s\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %s\t %d\t %d\t %s\t %d\t %d\t %f\t %d\t %f\t %f\t %d\t %f\t %d\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n',... taskversion, today, subID, gender, age, block, trial, file_object_1, object_1_id, object_1_rot, file_object_2, object_2_id , object_2_rot, cue, object_cue_id, object_cue_rot, uncue, object_uncued_id, object_uncued_rot, type_of_task, total_of_pings, position_odd_pings, total_of_pings_2, position_odd_pings_2, pingsareon, file_object_t, object_test_id, object_test_rot, file_object_t_uncued, object_test_id_uncued, object_test_rot_uncued, rt_resp_concrete, acc_trial_concrete, finalrot_concrete, rt_resp_concrete_uncued, acc_trial_concrete_uncued, finalrot_concrete_uncued, testinguncued, Onset_object_1, Onset_object_2, Onset_retrocue, Onset_taskcue, Onset_test, OnsetResp, Onset_feedback, Onset_retrocue_2, Onset_test_uncued,OnsetResp_uncued, Onset_feedback_uncued,Onset_thanks_uncued, Onset_ping(1), Onset_ping(2), Onset_ping(3), Onset_ping(4), Onset_ping(5), Onset_ping_2(1), Onset_ping_2(2), Onset_ping_2(3), Onset_ping_2(4),Onset_ping_2(5), trigger_object_1, trigger_object_2, trigger_retrocue, trigger_taskcue, trigger_object_concrete, trigger_object_abstract, pingcolorset, practice, righthanded, pingfixated(1),pingfixated(2),pingfixated(3), pingfixated(4), pingfixated_2(1), pingfixated_2(2), pingfixated_2(3),pingfixated_2(4), object_1_fixated, object_2_fixated,blocknulrep, fixtrh); else % Save results to file fprintf(outputfile, '%s\t %s\t %s\t %s\t %d\t %d\t %d\t %s\t %d\t %d\t %s\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %s\t %d\t %d\t %s\t %d\t %d\t %f\t %d\t %f\t %f\t %d\t %f\t %d\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n',... taskversion, today, subID, gender, age, block, trial, file_object_1, object_1_id, object_1_rot, file_object_2, object_2_id , object_2_rot, cue, object_cue_id, object_cue_rot, uncue, object_uncued_id, object_uncued_rot, type_of_task, pingsareon, file_object_t, object_test_id, object_test_rot, file_object_t_uncued, object_test_id_uncued, object_test_rot_uncued, rt_resp_concrete, acc_trial_concrete, finalrot_concrete, rt_resp_concrete_uncued, acc_trial_concrete_uncued, finalrot_concrete_uncued, testinguncued, Onset_object_1, Onset_object_2, Onset_retrocue, Onset_taskcue, Onset_test, OnsetResp, Onset_feedback, Onset_retrocue_2, Onset_test_uncued,OnsetResp_uncued, Onset_feedback_uncued,Onset_thanks_uncued, trigger_object_1, trigger_object_2, trigger_retrocue, trigger_taskcue, trigger_object_concrete, trigger_object_abstract, practice, righthanded, pingfixated(1), pingfixated_2(1), object_1_fixated, object_2_fixated,blocknulrep, trigger_fixcrosdev(1), trigger_fixcrosdev(2),trigger_fixcrosdev(3),trigger_fixcrosdev(4),trigger_fixcrosdev(5),trigger_fixcrosdev(6),trigger_fixcrosdev(7),trigger_fixcrosdev(8), trigger_fixcrosdev(9), visdegdis, fixtrh); end %% % % p1_name = stimuli_info.Item_Name(sequence_of_n_back(t,1),:); % % % Save results to file % fprintf(outputfile,'%s\t %s\t %d\t %f\t %f\n' ,... % today, p1_name, rt_catch, Onset_object_p1,OnsetResp); % % fprintf(outputfile, 'date\t object_name\t rt_resp_concreteonse\t Onset_object\t Onset_response\n'); %% Interblock MESSAGE if block~=next_trial_block ddo=block/nblocks baseRect = [0 0 W/4 W/32]; baseRect_done = [0 0 (W/4)*ddo W/32]; rectColorBase = [100 100 100]; rectColor_done = [0 200 10]; centeredRect = CenterRectOnPointd(baseRect, xCenter, yCenter); centeredRect_done = centeredRect; trd=centeredRect(1)+((centeredRect(3)-centeredRect(1))*ddo); centeredRect_done(3)=trd; % Draw the square to the screen. For information on the command used in % this line see Screen FillRect? Screen('FillRect', window1, rectColorBase, centeredRect); Screen('FillRect', window1, rectColor_done, centeredRect_done); Screen('TextSize',window1,18); msg=['Great! You finished the ',num2str(ddo*100),' % of the task']; DrawFormattedText(window1, msg, 'center', (H/2.5), textColor); DrawFormattedText(window1, ['Accuracy: ' num2str(mean(accuracy_con)*100)], 'center', (H/4.5), textColor); DrawFormattedText(window1, '[Press the space bar to continue]', 'center', (H/1.5), textColor); overviewTime = Screen('Flip',window1)-ExpStart; % first screen time Screen('TextSize',window1,40); % Wait for subject to press spacebar while 1 [keyIsDown,secs,keyCode] = KbCheck; if keyCode(KbName('space'))==1 break elseif keyCode(KbName('Q'))==1 endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile) end end % Counter for interblock message accuracy accuracy_con= []; accuracy_abs= []; end end end %% %% FINAL MESSAGE if practice msg=['Great! You finished the practice blocks']; else msg=['Great! You finished ',num2str(block),' of ', num2str(nblocks), ' blocks']; end Screen('TextSize',window1,18); DrawFormattedText(window1, msg, 'center', (H/4.5), textColor); DrawFormattedText(window1, '[Press the space bar to continue]', 'center', (H/1.5), textColor); overviewTime = Screen('Flip',window1)-ExpStart; % first screen time Screen('TextSize',window1,40); % Wait for subject to press spacebar while 1 [keyIsDown,secs,keyCode] = KbCheck; if keyCode(KbName('space'))==1 break end end %% END endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Subfunctions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% End the experiment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function endexperiment(window1,pahandle,outputfile, triggers_on,TB,ti,eyetracking,edfFile) if triggers_on % ti is the trigger id % Set the port to zero state 0 IOPort('Write', TB, uint8(0),0); WaitSecs(0.005) % Set Bit 0 (Pin 2 of the Output(to Amp) IOPort('Write', TB, uint8(ti),0); % Wait 2ms and reset the port to zero state WaitSecs(0.005) IOPort('Write', TB, uint8(0),0); WaitSecs(0.005) % Then disconnect/close the serial port object from the serial port IOPort('Close', TB); end if eyetracking==1 % mark zero-plot time in data file mel=num2str(ti) Eyelink('Message', mel); % STEP 8 % finish up: stop recording eye-movements, % close graphics window, close data file and shut down tracker Eyelink('StopRecording'); Eyelink('CloseFile'); Eyelink('ReceiveFile',edfFile, ['data_eyelink/' edfFile]) Eyelink('Shutdown'); end % Close audio settings (pahandle) PsychPortAudio('Close', pahandle); RestrictKeysForKbCheck([]); fclose(outputfile); Screen(window1,'Close'); close all sca; return end %% Detecting a that gaze is non-centered function [isoff]= gazeoff(W,H,fixtrh,gazeofftimelim,wentout) isoff=0; if Eyelink( 'NewFloatSampleAvailable') > 0 evt = Eyelink( 'NewestFloatSample'); if abs(round(evt.gx(1))-(W/2))>fixtrh|abs(round(evt.gy(1))-(H/2))>fixtrh %Eyes NOT fixated! startout=GetSecs; wentout=1; isoff=1; %eye not centered return end end end %% Detecting a that gaze is centered function [isin]= gazein(W,H,fixtrh,gazeofftimelim,wentout) isin=0; if Eyelink( 'NewFloatSampleAvailable') > 0 evt = Eyelink( 'NewestFloatSample'); if abs(round(evt.gx(1))-(W/2))<= fixtrh|abs(round(evt.gy(1))-(H/2))<= fixtrh %Eyes NOT fixated! isin=1; %eye centered return end end end %% Draw a fixation cross (overlapping horizontal and vertical bar) function drawCross(window,W,H,barColor) if nargin==3 barColor = [0 0 0]; end barLength = 16; % in pixels barWidth = 2; % in pixels %0.5; % number from 0 (black) to 1 (white) Screen('FillRect', window, barColor,[ (W-barLength)/2 (H-barWidth)/2 (W+barLength)/2 (H+barWidth)/2]); Screen('FillRect', window, barColor,[ (W-barWidth)/2 (H-barLength)/2 (W+barWidth)/2 (H+barLength)/2]); end %% Draw a fixation cross (overlapping horizontal and vertical bar) function drawCrossaround(window,W,H,PW,PH,barColor) if nargin==3 barColor = [0 0 0]; end barLength = 16; % in pixels barWidth = 2; % in pixels %0.5; % number from 0 (black) to 1 (white) Screen('FillRect', window, barColor,[((W-barLength)/2)+PW ((H-barWidth)/2)+PH ((W+barLength)/2)+PW ((H+barWidth)/2)+PH]); Screen('FillRect', window, barColor,[((W-barWidth)/2)+PW ((H-barLength)/2)+PH ((W+barWidth)/2)+PW ((H+barLength)/2)+PH]); end %% Draw a fixation cross (overlapping horizontal and vertical bar) function drawDotaround(window,W,H,PW,PH,barColor) if nargin==3 barColor = [0 0 0]; end barLength = 8; % in pixels barWidth = 8; % in pixels %0.5; % number from 0 (black) to 1 (white) Screen('FillOval', window, barColor, [((W-barLength)/2)+PW ((H-barWidth)/2)+PH ((W+barLength)/2)+PW ((H+barWidth)/2)+PH]); end %% Draw a fixation DOT (overlapping horizontal and vertical bar) function drawDot(window,W,H,barColor) if nargin==3 barColor = [0 0 0]; end barLength = 8; % in pixels barWidth = 8; % in pixels %0.5; % number from 0 (black) to 1 (white) Screen('FillOval', window, barColor, [(W-barLength)/2 (H-barWidth)/2 (W+barLength)/2 (H+barWidth)/2]); end % Screen(???DrawDots???, windowPtr, xy [,size] [,color] [,center] [,dot_type][, lenient]); %% Doing the timing job for delay between encoding (last item) and test function pausvec=pingT(npings,nodd,delth,pilth,minipi,maxsend,minstart) pausvec=NaN(1,npings+1); pausvec(1)=randsample(minstart:maxsend,1); % pause before first ping (pilth, 1; t=t-1; break end end WaitSecs(1); % Clear textures Screen(imageDisplay_in,'Close'); if t>imtotal; ttrue=0; end end end