07-13-2009 12:35 AM
I think you should quit all those loops and use a state machine mechanisme.
State 1 : Initialize controls
State 2 : Initialize DAQmx tasks
State 3 : Do some LCD stuff maybe
State 4 : Write an output value to the led's
State 5 : Read digital inputs
State 6 : Compare inputs with led's if not equal goto state 5, if equal goto state 7
State 7 : Update score and display
State 8 : Check stop button if pressed goto state 9, if not pressed goto state 4
State 9 : ...
... ...
This way your digital inputs will read continously while now it's only read after each game-level-time.
This way you also be able to determine the reaction time.
So, if I were you I would review the architecture of the code
07-13-2009 07:05 AM
07-13-2009 08:14 AM
07-13-2009 09:41 AM
DFGray wrote:
The only caveat I would give you is to avoid state machines which switch on strings - always use a typedef enum. This will make your future development much easier.
Absolutely!!! typedef is the only right way to go:)
But how to make a typedef?
Don't bother use this one as a start, just replace all the state names with your own state names.
07-13-2009 12:25 PM
And now the whole framework for a state machine. Please note that the code inside the states doesn't mean anything now since I removed most of the controls of that program.
Up to you now to:
You can download the Open G tools as discribed here
Share all of your new code so that we all can play that game
Good luck !
07-13-2009 12:27 PM
07-13-2009 10:39 PM
07-14-2009 11:16 AM
I've completed my code and can someone tell me if its working in sequence as stated below? I think i made a mess of things :S thanks..
1) Enter user name
2) Select level
3)Remaining time is displayed on the 7-segment
3) LEDs light up at random for 1 minute
4) Corresponding push button is pressed
5)Correct score? +1 mark
6) Remaining 5 secs, plays a beep.
7)End of game, another beep.
😎 Score is displayed on the LCD
9) Score displayed on monitor
10) Beep if new high score is set
07-14-2009 01:12 PM
One thing is for sure, you're using a state machine!
But is it well implemented? Not 100% sure about that
What I miss is an Idle state like in the statemacine I posted.
In the Idle state you should put the event structure and use it as an event structure.
Now you use an event structure as a level time out for the user.
You should implement the level time out as follow
Write a code to the led's
Add the level time out to the actual time (ticks since midnight)
In the Time out state of the event structure in the Idle state, compare that time with the actual time.
Is it overdue, go to the state "Write to LED's"
You're Stop button is in the "Start Timer" state 😞 Really confusing 😞
The user inputs name & Level selector should be in a state, same for the message at the end
Both cases of the case structure in "Compare read and write" go to "Write to LEDs" state ?!?
Skip the Wait function with 125ms because now you read you're inputs at maximum 8Hz
Clean up all those blue wires at the top of your VI. I didn't check what they are for but I'm sure there's a better way ... ...
I hope I didn't discourage you too much
07-14-2009 07:27 PM