-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcard.m
213 lines (182 loc) · 7.41 KB
/
card.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
%function MID2(isscan, subnum)
Screen('Preference', 'SkipSyncTests', 1);
global thePath; rand('state',sum(100*clock));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%subnum - subject number is 0 for practice, real number if it is a run
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subnum = input('subnumber: ');
whichrun = input('which run (1 or 2):');
% Add this at top of new scripts for maximum portability due to unified names on all systems:
KbName('UnifyKeyNames');
Screen('Preference', 'VisualDebuglevel', 3);
thePath.start = pwd; % starting directory
thePath.data = fullfile(thePath.start, 'data'); % path to Data directory
thePath.scripts = fullfile(thePath.start, 'scripts');
thePath.stims = fullfile(thePath.start, 'stimuli');
addpath(thePath.scripts)
addpath(thePath.stims)
% set up device number
if IsOSX
k = GetKeyboardIndices;
else
k = 1;
end
%%%%%% CONSTANT DECLARED VARIABLES %%%%%%%%%%%%%%%
text_size = 30;
ms=0.06; %duration of time post-target until responses are accepted (no keys accepted)
card_time = 1.5;
outcome_time = 1.5;
feedback_time = 1.5;
load([ thePath.start '/timing/run' num2str(whichrun) '.mat'])
%define intertrial fixation
fix_isi = run.isi2;
fix_iti = run.isi1;
trial_cond = run.cond;
backtick = '=';
mkdir(fullfile(thePath.data,num2str(subnum)));
Screen('CloseAll')
%%%SET UP SCREEN PARAMETERS FOR PTB
screens = Screen('Screens');
%Make sure this is alright
screenNumber = max(screens); HideCursor;
[Screen_X, Screen_Y]=Screen('WindowSize',screenNumber);
% USE THESE LINES FOR SET SCREEN
screenRect = [ 0 0 1024 768];
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
grey = white / 2;
[Window, Rect] =PsychImaging('OpenWindow', screenNumber, grey);
Hcenter=Rect(3)/2;
Vcenter=Rect(4)/2;
Screen('TextSize',Window,text_size);
Screen('FillRect', Window, 0); % 0 = black background
% LOAD STIMULI
[normBoundsRect, notused] = Screen('TextBounds', Window, 'loading stimuli....');
Screen('DrawText',Window, 'loading stimuli....', Hcenter-normBoundsRect(3)/2, Vcenter-normBoundsRect(4)/2, [255 255 255]);
Screen('Flip', Window);
WaitSecs(3)
%LOAD IN FIXATIONS
fix1 = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'cross'), 'png'));
fix2 = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'dot'), 'png'));
% LOAD CARD STIMULI
guess = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'card_guess'), 'png'));
outcome_HW = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'high_green'), 'png'));
outcome_LW = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'low_green'), 'png'));
outcome_HL = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'high_red'), 'png'));
outcome_LL = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'low_red'), 'png'));
outcome_N = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'neutral'), 'png'));
uhoh = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'uhoh'), 'png'));
card_1 = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'1'), 'png'));
card_2 = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'2'), 'png'));
card_3 = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'3'), 'png'));
card_4 = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'4'), 'png'));
card_5 = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'5'), 'png'));
card_6 = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'6'), 'png'));
card_7 = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'7'), 'png'));
card_8 = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'8'), 'png'));
card_9 = Screen('MakeTexture', Window, imread(fullfile(thePath.stims,'9'), 'png'));
low_cards = [card_1 card_2 card_3 card_4];
high_cards = [card_6 card_7 card_8 card_9];
[normBoundsRect, notused] = Screen('TextBounds', Window,'Get Ready for the Experiment!' );
Screen('DrawText',Window, 'Get Ready for the Experiment!', Hcenter-normBoundsRect(3)/2,Vcenter-normBoundsRect(4)/2,[255 255 255]);
Screen('Flip', Window);
%%%%%%%%%%%%%%%%%%%%%%%% BEGIN TRIAL LOOP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% record run start time (post disdaqs) CHECK ON WHEN IT SENDS TRIGGER
if IsOSX
getKey(backtick, k); % wait for backtick before continuing
else
getKey(backtick);
end
runST = GetSecs;
Screen('DrawTexture', Window, fix1);
Screen('Flip', Window);
WaitSecs(4);
for t = 1:length(trial_cond)
Screen('DrawTexture', Window, guess);
Screen('Flip', Window);
[keys, RT] = recordKeysNoBT(GetSecs, card_time, k, backtick);
Screen('DrawTexture', Window, fix2);
Screen('Flip', Window);
WaitSecs(fix_isi(t))
if sum(strcmp(keys(1), {'1' '2'})) < 1
Screen('DrawTexture', Window, uhoh);
Screen('Flip', Window);
WaitSecs(outcome_time)
Screen('DrawTexture', Window, outcome_N);
Screen('Flip', Window);
WaitSecs(feedback_time)
else
if trial_cond(t) == 1
if strcmp(keys(1),'1')
disp_card = Shuffle(low_cards);
disp_card = disp_card(1);
elseif strcmp(keys(1), '2')
disp_card = Shuffle(high_cards);
disp_card = disp_card(1);
end
imgsize=size(disp_card);
Screen('DrawTexture', Window, disp_card);
Screen('Flip', Window);
WaitSecs(outcome_time)
Screen('DrawTexture', Window, outcome_HW);
Screen('Flip', Window);
WaitSecs(feedback_time)
elseif trial_cond(t) == 2
if strcmp(keys(1),'1')
disp_card = Shuffle(high_cards);
disp_card = disp_card(1);
elseif strcmp(keys(1), '2')
disp_card = Shuffle(low_cards);
disp_card = disp_card(1);
end
Screen('DrawTexture', Window, disp_card);
Screen('Flip', Window);
WaitSecs(outcome_time)
Screen('DrawTexture', Window, outcome_HL);
Screen('Flip', Window);
WaitSecs(feedback_time)
elseif trial_cond(t) == 3
if strcmp(keys(1),'1')
disp_card = Shuffle(low_cards);
disp_card = disp_card(1);
elseif strcmp(keys(1), '2')
disp_card = Shuffle(high_cards);
disp_card = disp_card(1);
end
Screen('DrawTexture', Window, disp_card);
Screen('Flip', Window);
WaitSecs(outcome_time)
Screen('DrawTexture', Window, outcome_LW);
Screen('Flip', Window);
WaitSecs(feedback_time)
elseif trial_cond(t) == 4
if strcmp(keys(1),'1')
disp_card = Shuffle(high_cards);
disp_card = disp_card(1);
elseif strcmp(keys(1), '2')
disp_card = Shuffle(low_cards);
disp_card = disp_card(1);
end
Screen('DrawTexture', Window, disp_card);
Screen('Flip', Window);
WaitSecs(outcome_time);
Screen('DrawTexture', Window, outcome_LL);
Screen('Flip', Window);
WaitSecs(feedback_time)
elseif trial_cond(t) == 5
Screen('DrawTexture', Window, card_5);
Screen('Flip', Window);
WaitSecs(outcome_time)
Screen('DrawTexture', Window, outcome_N);
Screen('Flip', Window);
WaitSecs(feedback_time)
end
end
Screen('DrawTexture', Window, fix1);
Screen('Flip', Window);
WaitSecs(fix_iti(t)) ;
output.response(t) = keys(1);
output.RTs(t) = RT(1);
end
save([thePath.data '/' num2str(subnum) '/card.mat'], 'output')
sca;