Phidgets are a set of "plug and play" building blocks, some low-cost electronic components that you can control from your personal computer via USB. They provide you with some extra input/output methods beyond the classic mouse + keyboard + screen.

As Harold Thimbleby mentioned in his book Press On, phidgets are a very nice way to get into hardware programming, as you may want to build real systems, not on screen or web browser simulations : phidgets are so-called because they are the physical equivalent of on-screen widgets (Windows Gadgets).

Yes I know, it looks horrible but hey, everyone needs to start somewhere...

We used it primarily to go along with a flight simulation game we programmed, we used force sensors for shooting, a joystick for direction, RFID tags for user authentication and a rotation sensor to regulate the game speed. The game events where reflected through a LCD screen and a few LED indicators.

(Thanks for reading so far. The rest is for the nerds only. This is the part where we briefly discuss the key technical details.)

The game itself was written in C#. It was inspired from a Riemers XNA tutorial. The key parts of the code include the navigation system:

if (keys.IsKeyDown(Keys.Right))

leftRightRot += turningSpeed;

if (keys.IsKeyDown(Keys.Left))

leftRightRot -= turningSpeed;

float upDownRot = 0;

if (keys.IsKeyDown(Keys.Down))

upDownRot += turningSpeed;

if (keys.IsKeyDown(Keys.Up))

upDownRot -= turningSpeed;

The aircraft keeps moving forward automatically and the above code is used to control the rotational movements. One of our challenges was to incorporate the phidget code for the joystick into this part of the code such that the joystick behaves as arrow keys.

First of all we created a new input wrapper which is the class that contains the sensor change handler to detect any changes in the movement of the joystick. The input wrapper class implements the interface kit object which detects any input from any phidget

The first section of the next code controls the x axis of the joystick. The output values of the joystick are between 0 and 999, so for any value greater than 500 the plane would rotate to the right and any value less than 500 the plane would rotate to the left. The second part of the code is used to control the Y axis of the joystick. This time any value greater than 500 would rotate the plane so it's facing upwards while any value less than 500 will rotate the plane so it's facing downwards.

if(iw.XJoystick>550)

leftRightRot = (iw.XJoystick-500)/10000;

if (iw.XJoystick < 450)

leftRightRot = (iw.XJoystick-500)/ 10000;

if (iw.YJoystick > 550)

upDownRot = (iw.YJoystick - 500)/10000;

if (iw.YJoystick < 450)

upDownRot = (iw.YJoystick - 500) / 10000;

The LCD screen was used to display the current player and their score. The user must scan their id to start the game or the game wouldn’t start. The RFID phidget was used to detect the identity of the current playing user. First of all we created a text LCD wrapper and an RFID wrapper which contain the various event handlers. The RFID detects if a tag is present; if not a message appears on the LCD screen asking the user for their tag

TextLCDWrapper tlw = newTextLCDWrapper();

RFIDWrapper rw = newRFIDWrapper();

while (rw.tag == null || rw.tag.Length < 2)

{

tlw.JustTyped("Tag, Please!");

}

When the user scans their tag the RFID will detect if the user is registered to play the game or not and display the relevant message on the LCD screen

The rotation sensor will be used to control the speed of the plane. The values of the rotation sensor are obtained through the input wrapper class, previously mentioned when describing the joystick. The more you turn the rotation phidget the more the speed increases

gameSpeed = iw.RotationValue/100;

The following code creates a new bullet every time the space bar is pressed provided the previous bullet was fired more than 100 milliseconds ago

if (keys.IsKeyDown(Keys.Space))

{

double currentTime = gameTime.TotalGameTime.TotalMilliseconds;

if (currentTime - lastBulletTime > 100)

{

Bullet newBullet = newBullet();

newBullet.position = xwingPosition;

newBullet.rotation = xwingRotation;

bulletList.Add(newBullet);

lastBulletTime = currentTime;

}

}

Our task was to implement four sensors to control the bullets being fired from the plane. The values of the force sensor are also obtained through the input wrapper class. The following code now creates a new bullet of type 3 every time the force sensors are pressed