Having trouble setting several timers where someone has to answer a question before time runs out or the answer is considered wrong. Also records time answered
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi. I am working on a project where I need to record how long it takes someone to answer 3 separate questions, while a timer is running for the entire experiment.
Update: I can do this all on 1 timer, but I need to record the times for the various steps.
I have tried to make a timeline to show what I mean
Basically, I need a master timer running from the beginning.
Next, an EasyTimer starts and can run up to 20 seconds. If the person answers before the 20 seconds is up, I want the time they answered recorded. If they don't, then that question is marked wrong.
The MedTimer is basically the same thing, but it can run up to 45 seconds. The HardTimer is the same thing, but it can run up to 1 minute.
I can't figure out how to make, start, and stop the timers. I have read the documentation, several examples, and several questions but I still don't understand it. Once I get that figured out, I think I can handle recording the times. Can someone help me with this please? I have inserted my code below.
tT=timer; %timer for total time
start(tT);
tEMax=20; %Easy problem timer = 20 sec
tMMax=40; %Medium problem timer=45 sec
tHMax=60; %Hard problem timer= 60sec
fprintf('Directions: Complete the following Math problems in your head, then type the answer on the number pad. You will have up to 1 minute to answer each question. Please press any button to continue.\n\n')
pause;
% Easy problem: __*10
%reasy=randi(99); %creates a random integer between 1 and 99
%For easy, the problem is 76*10, where 76 was randomly generated
ECorAns=76*10; %correct answer
tE=timer('StartFcn', @(~,~)disp('Easy Problem'), 'TimerFcn', @(~,~)rand(1));
start(tE);
while tE <= tEMax
easAns=input(' 76 \n x10 \n ')
stop(tE);
end
if tE > tEMax
stop(tE);
easAns=0;
fprintf('Out of time');
end
% Medium Problem - the randomly generated numbers to multiply were 68 and 8
MCorAns=68*8;
tM=timer;
start(tM);
while tM <= tMMax
medAns=input(' 68 \n x8 \n ')
stop(tM);
end
if tM > tMMax
stop(tM);
easAns=0;
fprintf('Out of time');
end
% Hard Problem - the randomly generated numbers to multiply were 89 and 14
HCorAns=89*14;
tH=timer;
start(tH);
while tH <= tHMax
hAns=input(' 89 \n x14 \n ')
stop(tH);
end
if tH > tHMax
stop(tH);
hAns=0;
fprintf('Out of time');
end
stop(tT);
fprintf('Experiment Ended. Thank you!')
PS. If this would be easier to do with a GUI, I am willing to do that, but I'll need a lot of help with that too as I've never made a GUI before
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!