pass the TIME away

Status
Not open for further replies.
all the delays are to see the led come on, indicates code progression.
Am configuring a timer to detect a button press and timing for 7 seconds.
I discovered that I need to internalize the timer within the sub routine.
In the mean time been researching how to read a remote IR signal (back to Christmas Star idea) but everything I find deals with Arduino. May have to invest in a starter set?
 
You CAN'T use delays for any reason while trying to capture the time of button presses. FOR ANY REASON.

If button is pressed during a delay, it will not be detected.
 
am aware of that. attempting maybe a FOR NEXT loop That way nothing stops hopefully
 
Code:
dim ms as word
dim button1_time as word
dim button2_time as word

//DEEP STAGING
Timer.Stop
ms = 0
button1_time = 0
button2_time = 0
Timer.Start

   repeat        //this section needs to exit AFTER 7 SECONDS
       if (Go_1 = 0) and (button1_time = 0) then    // player1 button press...
            blue1=1
            blue2=0
            button1_time = ms                // only record first button press
        endif
       if (Go_2 = 0) and (button2_time = 0) then    // player2 button press...
            blue1=0
            blue2=1
            button2_time = ms                // only record first button press
        endif
   until (ms >= 7000)        //need to time for 7 seconds
 
For those of us who don't understand exactly what MrDEB is trying to do, here is an online simulator.


It took me a minute to figure out how to use the simulator.

Press the [pre-stage] button.

The button changes to [go].

Press and hold the [go] button, which starts the countdown. The instant the green light illuminates, release the [go] button. Your reaction time will be shown.
 
Last edited:
close but it gives the idea of what I am trying to simulate.

There are apparently different variations on the theme, with variations in the exact light sequence.

But I think there is an error in your logic of separating staging out from the rest of it.

[Blue lights cycle]

and

[Test reaction time]

are not separate stand-alone events.

If you press (release in the online simulator) the [go] button while staging is counting down (which is before the red and yellow LEDs are illuminated), it's a foul. The same as if you hit it while the red or yellow LEDs are illuminated. Or, simplified, pressing [go] at any point before the green LED is illuminated is a foul.

Ok, this just got much easier. Back with an illustration shortly.
 
This is a simple, very linear task, as shown by the illustration. The exact sequence and timing of the LEDs may need to be adjusted because I've lost track, but follow along.

Set the mS variable to –8000, the total time of staging, red and yellow LEDs before the green LED is illuminated. When staging starts, increment mS. It will start counting up towards zero (i.e., –7999, –7998, –7997...)

The blue LED is illuminated until mS > -1000

When mS reaches –1000mS, the red LED is on

When mS reaches –500mS, the yellow LED is on

When mS reaches zero, the green LED is on

Note: the above lines are literally 4 if/then statements.

During this entire event, the go buttons are monitored. When a button is pressed, mS is captured, and any addition presses are ignored (got to love me some boolean you know). If mS is negative, it's a foul. If mS is positive, it's the reaction time.

That's a total of about 8 if/then statements in the main program loop, plus a sub routine to display the results.

 
Why would you want to ruin this with a simple, concise, and understandable example of the desired results?

Although I did give you a thumbs up for the effort!
 
It's a pretty straight forward task once you understand exactly what's needed.

There are variations in how many lights illuminate in what time intervals; it would be pretty simple to code for all the options.
 
In the interest of heading off "I tried this but it didn't work" creativity, the variable type used for mS in my scheme must support negative numbers, i.e., be either INTEGER or LongInt type.

 
I like the description that Jon posted but need to decipher why go with negative numbers? Just asking.
I printed out your description and going to run it to see what happens.
 
I like the description that Jon posted but need to decipher why go with negative numbers? Just asking.
I printed out your description and going to run it to see what happens.

I believe my explanation about is clear and concise. But to make it more so, added a few words to the picture.

 
I am trying to use Jons advice but it won't compile?
-7000 do I need to use it as an integer?
 
In the interest of heading off "I tried this but it didn't work" creativity, the variable type used for mS in my scheme must support negative numbers, i.e., be either INTEGER or LongInt type.

Guess that didn't work out very well, did it?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…