Author Topic: Simple joystick  (Read 214 times)

Anders

  • Newbie
  • *
  • Posts: 2
Simple joystick
« on: May 05, 2019, 09:08:56 am »
Hi,

I'm a total noob and was wondering if there are any easy tutorials or ready to use code for a simple joystick out there? This is for use with windows software that supports joysticks to control pan and tilt on cameras.
So all I really need is x and y axis.
I have Digispark Pros and a joystick module, and have looked at the code example for the joystick library, but didn't get any wiser.

Has anyone made something like this before?

Thanks!

Anders

  • Newbie
  • *
  • Posts: 2
Re: Simple joystick
« Reply #1 on: July 06, 2019, 01:55:48 pm »
^

granzeier

  • Jr. Member
  • **
  • Posts: 53
Re: Simple joystick
« Reply #2 on: July 07, 2019, 03:38:06 am »
A normal aalog joystick consists of two variable resistors and one, or two, push buttons (there are the cheaper digital only joysticks, but they require more inputs than the Digispark has). The Digispark has four analog inputs (see Analog Read in the tutorial - https://digistump.com/wiki/digispark/tutorials/basics,) but two of them (analogRead(2) and analogRead(3) ) use the pins for USB communications. That leaves two analog input pins for the two variable resistors, and the remaining pins for up to two fire buttons.

As a beginner, you would first want to get yourself familiar with reading the variable resistors and the buttons. Put together a simple breadboard circuit and plug some wires into the pins of the joystick (check out the pinout on Wikipedia's article about game ports [joysticks] - https://en.wikipedia.org/wiki/Game_port,) and then write some simple programs for the Digispark to read the values and send them to the IDE's terminal. Play with that until you get good readings all the time.

Once you get all that going, you will need to research how Windows reads a joystick position off of USB. I don't have any more Windows systems, and do not know how that would be done, but I would start out looking at the DigiKeyboard routine. You could try the digital joysticks, because the DigiKeyboard does provide for the up, down, left and right key strokes. But that would require additional hardware to cover the additional inputs required for the joystick. Of course, you could do like we did back in the seventies and just set up a simple direction joystick using the arrow keys (via DigiKeyboard,) and use the space bar for the fire button.