function [sens, Par] = JA_check_hands_Warming_Up(Par,s) % it checks that before the onset of the trial sensors sense enough pressure % threshold to be exceeded threshold = 50; % washout what's in the serial port scrittura(s); [~, ifi_as] = JA_frames_function(1, Par.ifi); initial_test = 0.5; %secs t = 0; tic; while t <= initial_test t = toc; % check if after 0.5 s the sensors are fine --> if so exit the function [sens] = JA_inside_fun_READ_WRITE(); end % if any sensor does not sense enough pressure if sens.SBJ_DCG < threshold... || sens.SBJ_RISP < threshold while 1 % run the while loop until all the sensors sense pressure above threshold for 3 consecutive seconds % ask PTP and CF to put fingers on sensors by printing it on % the screen JA_inside_fun_FINGER_ON_SENSORS('Dita sui sensori!:-)') % wait 1 second WaitSecs(1.0); % check sensors again [sens] = JA_inside_fun_READ_WRITE(); % if any of the sensors still do not feel enough pressure if sens.SBJ_DCG < threshold || sens.SBJ_RISP < threshold % go back to the while loop disp('not enough') continue else % in case all sense enough pressure --> start count down of 3 seconds [sens] = JA_inside_fun_FOR_CYCLE_COUNT_DOWN(); disp('out of for cycle') % if the for loop ends --> sensors sensed enough pressure % --> return end disp('control last sensor cheking') if sens.SBJ_DCG > threshold... && sens.SBJ_RISP > threshold % if the cycle inside JA_inside_fun_FOR_CYCLE_COUNT_DOWNend well, exit function disp('great!') return else disp('not_enough...do it again') end end % fi the while loop spits enough pressure on sensors % recorded on a period of 0.5 seconds % exit the function providing sensor values as output end %end disp('good initial conditions') %JA_ready_screen() return % if initial conditions are good, exit function function [sens] = JA_inside_fun_READ_WRITE() % get baseline pressure tmp_value = scrittura(s); % slpit the 3 values that are read from the three pins in arduino tmp2 = (strsplit(tmp_value, '_')); % assign each value to the correct object (the SBJ_DCG is needed to check participnats' engagement effect) bs = str2double(tmp2); sens.CF = bs(1); % sensor used by CF to sens.SBJ_DCG = bs(2); sens.SBJ_RISP = bs(3); end function [] = JA_inside_fun_COUNT_DOWN(number) cd_num = num2str(number); % draw black 'hidden screen' Screen('FillRect', Par.window, [0 0 0], Par.screen_dimensions); % draw a count down starting from 3 on the hidden screen Screen('TextSize', Par.window, 80); DrawFormattedText(Par.window, cd_num, 'center',... 'center', [0 1 1]); [Par.VBL] = Screen(Par.window, 'Flip', Par.VBL+Par.ifi,1); end function [] = JA_inside_fun_FINGER_ON_SENSORS(text) %text = 'Dita sui sensori!:-)'; % draw black background Screen('FillRect', Par.window, [0 0 0], Par.screen_dimensions); % set text size Screen('TextSize', Par.window, 80); % draw text 'fingers on the sensors!' on the 'hidden screen' DrawFormattedText(Par.window, text, 'center',... 'center', [0 1 1]); % flip the 'hidden screen' to the 'front screen' [Par.VBL] = Screen(Par.window, 'Flip', Par.VBL+ifi_as,1); end function [sens] = JA_inside_fun_FOR_CYCLE_COUNT_DOWN() for last_count = 3:-1:1 % display count down JA_inside_fun_COUNT_DOWN(last_count) % check sensors --> are they still ok? [sens] = JA_inside_fun_READ_WRITE(); % if any of them do not feel eonough pressure break the for % loop --> this will bring the script to the beginning of %the while loop if sens.SBJ_DCG < threshold... || sens.SBJ_RISP < threshold ...go back to the 'while loop' before the for loop disp('at least one sensor does not sense...go back to while'); break end % wait before starting the next count WaitSecs(0.5); end end end