Gadgeteer Joystick 2.1 Example

The Joystick 2.1 module from GHI Electronics is a fun and easy to use joystick controller.  Joystick controllers feel like they’re going the way of the dinosaur because of touch screens. However, they’re excellent for teaching velocity based movement across a screen within a boudary.  This is basis for all games.

The code can be found on my Gadgeteer GitHub repository.  You can find out more about the module on the Gadgeteer Page.

Using the Joystick Module to move an ellipse around the screen.

First you need to get the basic screen dimensions

Get the current joystick center position. Note: There is some noise when asking the joystick for it’s position. The X/Y values vary about +/-0.02.

Start the joystick thread to listen for postion changes

My joystick thread simply loops and calls a MoveCursor function

The move cursor does all the fun stuff. First, determine the new position. If it’s has not moved beyond the 0.03 noise limit, return.

Did we go off the screen? If yes, then show up on the other side.

Set the current position and draw an ellipse there… finally!

Share this Post