|
Reaction Timer
#262619
04/24/09 22:07
04/24/09 22:07
|
Joined: Apr 2009
Posts: 27 Silicon Valley
Dillinger
OP
Newbie
|
OP
Newbie
Joined: Apr 2009
Posts: 27
Silicon Valley
|
Hi Ya'll, New to Lite-C and C programming. I wanted to measure reaction time in thousandths of a second like so: "Your reaction time was: 0.7653 seconds" I tried a bunch of things; I tried starting with timer() and divide the microseconds by 1000000. but when you go over 1 second it flips to a negative number so I don't think it's good for that. I was trying to use time_frame, but the results seem chunky and not very accurate. Using seconds and dividing that would only give me a rounded off number as well, right? Does anybody know how I can accurately time your reaction in 1000ths or so? Thanks Here's a rudimentary example:
#include <acknex.h>
#include <default.c>
fps_max = 60 ;
var randomNumber = 0 ;
var asciiInput = 0 ;
var elapsed_time = 0 ;
var reactionTime = 0 ;
var counter = 0 ;
var guessing = 0 ;
STRING* tempString = " " ;
PANEL* onscreenVariables =
{
digits( 35, 20, "randomNumber = %0.f", Arial#20b, 1, randomNumber ) ;
digits( 35, 34, "elapsed_time = %0.5f", Arial#20b, 1, elapsed_time ) ;
digits( 35, 82, "time_frame = %0.5f", Arial#20b, 1, time_frame ) ;
digits( 35, 98, "reactionTime = %0.5f", Arial#20b, 1, reactionTime ) ;
flags = VISIBLE;
}
function main()
{
video_set( 1024, 768, 32, 2 ) ;
random_seed( 0 ) ;
// MAIN GAME LOOP //
while(1)
{
if (!guessing)
{
randomNumber = 0 ;
wait( 400 ) ;
randomNumber = ( integer( random(4) ) + 1 ) ;
guessing = 1 ;
}
if ( guessing )
{
asciiInput = inchar( tempString ) ;
elapsed_time = time_frame * 1000 / 16 ;
if ( randomNumber == ( asciiInput - 48 ) )
{
reactionTime = elapsed_time ;
elapsed_time = 0 ;
guessing = 0 ;
}
}
wait(1);
}
}
|
|
|
Re: Reaction Timer
[Re: Dillinger]
#262624
04/24/09 23:18
04/24/09 23:18
|
Joined: Apr 2006
Posts: 737 Ottawa, Canada
Ottawa
User
|
User
Joined: Apr 2006
Posts: 737
Ottawa, Canada
|
Hi! This might help  Go to the search area at the top and write timer. There was a discussion on this topic a while back ...you will find it. Ottawa 
|
|
|
Re: Milliseconds
[Re: Dillinger]
#284592
08/14/09 05:58
08/14/09 05:58
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Try this... Any problems or queries, let me know.
//////////////////////////////////////////////////////////////
// ms_timer() = 'timer()'-like function for milliseconds
//////////////////////////////////////////////////////////////
// Usage:
// ms_timer(1); //reset timer to zero
// var xxx = ms_timer(0); //retrieve milliseconds since last reset
//////////////////////////////////////////////////////////////
//
long __stdcall GetTickCount();
#define PRAGMA_API GetTickCount;kernel32!GetTickCount
long ms_timer(var init)
{ static long StartTime = GetTickCount();
if(init) StartTime = GetTickCount();
return(GetTickCount() - StartTime);
}
//
//////////////////////////////////////////////////////////////
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|