For the next "Global game jam", I'm part of one developing team, my job will be making a light gun, so we can shoot some targets on our computerscreen.
At this moment we worked out the hardware: 1 button to shoot 1 photodiode / phototransistor to control if we where shooting right
How does a lightgun works? When you pull the trigger, the screen blackens out for a frame and a frame later the target will be a white cirkel or cube in a black frame. If we were aiming right the photodiode detects the light of the white cirkel and the program or game knows if you shot the target. What if we have more targets? After the screen blackens out, we flash every target after each other.
Of course it has to go very fast. And thats where our problem starts. The programming language for our game will be Java so we wil use a serial connection between the game and the arduino board.
The program flow will be some like this:
- The trigger button is pressed and arduino will send a specified character over the serial connection to the game.
- The game will show a black screen
- The game will show a white circle around target01
- The game will show a white circle around target02
- The game will show a white circle around target03
- Arduino send over the serial connection a code back (100 or 010 or 001 or 000)
- The game will kill the matching target.
How can I sync the arduino and the game, because serial connection will not be in sync all the time. Is it plausible to sync a arduino with a computer screen.
One solution could be: Taping a photo diode to the corner of the screen and constant alternate that corner between black and white and use that corner as a sync/data line to tell when the screen is ready to show the targets. For example: make one white corner black after the button is pressed and the arduino knows when to capture the white targets.
But that will makes everything more complex.
If you can think of other easier solutions, let us know, we would be very pleased to find out. Smiley