How do analog joysticks work




















We will read the measurement from two analog inputs and one digital input. Then we will display the result on serial monitor.

The sketch starts by initializing connections of Joystick module on the Arduino. We also start the serial communication. First we will program our Arduino to spit values of x-axis, y-axis and button state on serial port. We will receive these values coming from serial port in Processing IDE. These values can then be used to animate joystick position. Of course this project could be extended to animate characters, surveillance projects or controlling unmanned vehicles. To start with, we need to program our Arduino to spit values of x-axis, y-axis and button state on serial port.

The program is quite same as above except the values we print on serial monitor are comma-separated. Why comma-separated? Because this is a popular format for transferring data from one application to another.

Keep your Arduino plugged and Run following Processing code. First we need to import serial library for reading values coming on serial port.

This is all made possible thanks to the design of the joystick consisting of two potentiometers and a gimbal mechanism. The goal of the joystick is to communicate motion in 2D to a computer or Arduino in this case by converting analog readings to digital. We refer back to the reliable potentiometer which it confers an analog meaning to the movement of the joystick. When you rotate the joystick, the thumb handle moves a narrow rod that sits in 2 rotating, slotted shafts gimbal.

One of the shafts allow motion in the X-axis left and right while the other allow motion in the Y-axis up and down. Tilting the stick forward and backward pivots the Y-axis shaft from side to side. Tilting it left to right pivots the X-axis shaft. When you move the stick diagonally, it pivots both shafts Harris, Attached to each shafts are potentiometers that interpret the position of the rod as analog readings.

Of course the analog signal will then be converted into digital signals using an analog-to-digital converter involving capacitors. By: Tom Harris. In order to communicate a full range of motion to the computer, a joystick needs to measure the stick's position on two axes -- the X-axis left to right and the Y-axis up and down.

Just as in basic geometry, the X-Y coordinates pinpoint the stick's position exactly. In the standard joystick design, the handle moves a narrow rod that sits in two rotatable, slotted shafts. Tilting the stick forward and backward pivots the Y-axis shaft from side to side. Tilting it left to right pivots the X-axis shaft. Hence the values on each analog channel can vary from 0 to The home position for the stick is at x,y, If the stick is moved on X axis from one end to the other, the X values will change from 0 to and similar thing happens when moved along the Y axis.

On the same lines you can read position of the stick anywhere in upper half hemisphere from combination of these values. It is usually not enough to read the analog values, you might want to map it to a display or any other interface.



0コメント

  • 1000 / 1000