Arduino lightgun interfacing with Java

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

sounds like "Duck Hunt" old school Nintendo game.

as you've noticed, serial isn't fast enough for this (without some serious hacking) - maybe check out i2c, this is widely supported, plus its implemented on Wii controllers. just a thought, might make your speed issues easier.


Wont it depend on what type of screen your using and it's refresh rate. I think you need to know very accurately just were the raster scan of the electron beam (or what ever the modern equivalent of that is, if it even works the same) .. Is this how it work's or am i thinking of an old style light pen. I reckon it's got to be similar. Surely most of the work is going to be in the computer side of things. I doubt you could do it in java i could be wrong. I would think it's very platform dependent what with there been so many different types of monitors and graphics card setups. You would be better of hacking a Kinetic or something