The joystick port is a quick and dirty analog to digital converter that can be used for many more things than just joysticks and gamepads. In this project I used the joystick port to input the value of two LDRs (Light Dependent Resistors) to be used to calculate the velocity of an object. Two flashlights (or other sources of light) are placed in front of the two LDRs. The computer records the time between the blockage of the first and second sensors. Using the equation v = d / t the computer calculates the average velocity of the object.
The circuit connects to the PC via a joystick/game port. Two 100k resistors are required to make sure that the resistance never surpasses the joystick's limit when its dark. Beyond 100k the PC registers the value as zero and causes the program to function improperly. Below is a circuit diagram/schematic:
To limit the amount of ambient light to the LDRs I hot glued them in place in two halves of an empty ballpoint pen. I then glued each to a large washer, which acts as a base. Diagram:
Next I wrote a simple program in QBASIC. Stick(n) function gets the integer value of a sensor where n = the input number. 0 = Joystick #1 X-axis and 1 = Joystick #1 Y-axis (2 and 3 are for Joystick 2 and we do not need to use them.) Below is the source code of the program (which is a bit messy...) The important parts are marked in yellow.
Important note: the DOS emulator in NT, 2000, and XP does not support the game port. So, you must use a DOS emulator such as DOSBox, which is a free download. Also, the object must first pass through the x-axis sensor before passing through the y-axis sensor. This is due to the nature of my program. Below is a screenshot of the running program:
Download exe | Download QBASIC source code
View test movie
Questions/Comments may be sent to adwiens AT gmail DOT com.