Reaction game

hi guys,

we were wondering if it is possible to write a code so that if like for instance a led blinks 2 times you have to press a button but is you do not press it on time something else happens but how do you write the code to say that you have to press the button after something is happend otherwise something else happens if you are not in time????

Thank you,

Fred & Gijs

Yes, is possible, start from these

Blink Without Delay

Demonstration code for several things at the same time

fredengijs:
we were wondering if it is possible to write a code so that if like for instance a led blinks 2 times you have to press a button but is you do not press it on time something else happens but how do you write the code to say that you have to press the button after something is happend otherwise something else happens if you are not in time????

If you can describe it unambiguously in plain English words, you can program it.

So before writing the C code:
Describe the full programming logic with all details in plain English words, unambiguously!

Perhaps a simple solution to your problem is a code for a "Finite State Machine" (FSM). FSMs are optimal solutions, if your problem can clearly be split up into different "states" like:

  • before blink
  • during blink
  • after blink
    only one state at a time being the active state, and you can clearly define under which conditions one state switches into another state and what has to happen during one of the states is active.