function [max_force_left, max_force_right] = ISP_MoBi_get_maximal_force(window, misure_schermo, ifi,s,time_x_avg, estimation_time) [ifi_af, ifi_as, ifi_nf, ifi_ns] = MoBI_frames_Brescia(ifi, ifi); [onesec_af, onesec_as, onesec_nf, onesec_ns] = MoBI_frames_Brescia(1, ifi); %% INSTRUCTION FOR FORCE ESTIMATION LEFT SIDE Screen('FillRect', window, [0 0 0], misure_schermo); % "at the Go signal press the sensor in the left hand as strong as you can until the stop signal" Screen('TextSize', window, 20); DrawFormattedText(window, 'al "Via!" premi il sensore SINISTRO pił possibile fino allo "stop" ', 'center',... 'center', [1 1 1]); [VBL]=Screen(window, 'Flip', ifi, 1); %% WAIT FOR A KEYBOARD TYPING KbStrokeWait %% start the estimation % DISPLAY 1, 2, 3, Go! (Via!) for p = 1:3 Screen('FillRect', window, [0 0 0], misure_schermo); Screen('TextSize', window, 80); DrawFormattedText(window, num2str(p), 'center',... 'center', [1 1 1]); [VBL]=Screen(window, 'Flip', VBL+onesec_as, 1); end % Go! Screen('FillRect', window, [0 0 0], misure_schermo); Screen('TextSize', window, 80); DrawFormattedText(window, 'Via!', 'center',... 'center', [1 1 1]); [VBL]=Screen(window, 'Flip', VBL+onesec_as, 1); % set time required for the estimation estimation_max_force_time = estimation_time; % wait 0.2 sec after Via! appeared... WaitSecs(0.2) %% READ VALUES FROM A0 (FIRST PIN) --> GET MAXIMAL FORCE for t = 1:round(estimation_max_force_time/ifi_ns); % for the number of frames in the estimation time... % ardunio writes onto the serial port, matlab reads tmp_value{t} = MoBi_scrittura(s); % strsplit the 3 values that are read from the three pins in arduino tmp2{t} = (strsplit(tmp_value{t}, '_')); % convert the reading from string to double type sensore_val(t) = str2double(tmp2{t}{1}); % do the process at each frame... Screen('FillRect', window, [0 0 0], misure_schermo); Screen('TextSize', window, 80); DrawFormattedText(window, num2str(sensore_val(t)), 'center',... 'center', [1 1 1]); [VBL]=Screen(window, 'Flip', VBL+ifi_as, 1); end % calculate mean force step =(round(time_x_avg/ifi,0)); for rng = 1:size(sensore_val,2)-step sensore_val_avg(rng) = mean(sensore_val(1,rng:rng+step),2); end % find the maximal value from the recorded series max_force_left = max(sensore_val_avg); % stop recording and show STOP label Screen('FillRect', window, [0 0 0], misure_schermo); Screen('TextSize', window, 80); DrawFormattedText(window, 'Stop', 'center',... 'center', [1 1 1]); [VBL]=Screen(window, 'Flip', VBL+onesec_as, 1); % wait before going on (we do not care about precision time here) WaitSecs(0.5) %% SET MOCK VALUE FOR FORCE max_force_right = 900; end