123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- function [sens,Par,s] = JA_check_hands_Main_Experiment(Par, s)
- % it checks that before the onset of the trial sensors sense enough pressure
- % threshold to be exceeded
- threshold = 50;
- [~, ifi_as] = JA_frames_function(1, Par.ifi);
- initial_test = 0.5; %secs
- t = 0;
- tic;
- scrittura(s);
- 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.CF < threshold ...
- || 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.CF < threshold || 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.CF > threshold ...
- && 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')
- 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.CF < threshold...
- || 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
|