Arduino improve articles 12- biaxial joystick button

Biaxial joystick button

Rocker generally widely used in model aircraft, video, remote control cars, head and other equipment, many devices are often used with a screen input control joystick as menu selection. This introduction biaxial joystick button.

1. Introduction The biaxially rocker button

The biaxially rocker button mainly by a key switch and potentiometer 10K two compositions, with two potentiometers rocker rotation angle corresponding to the output voltage value respectively X, Y-axis, the joystick is pressed in the Z-axis direction may trigger the touch of a button. Under the action of a mechanical supporting structure, no external twisting rocker initial state, two potentiometers are in an intermediate position range.

Joystick Module

Output pin will be different manufacturers module rocker keys vary, but there will be VCC, GND supply pin and the X, Y, Z output pin.

Joystick port

2. Experimental Materials

  • Uno R3 Development Board
  • Supporting USB data cable
  • Bread plate and supporting cables
  • The biaxially module rocker keys

3. Experimental Procedure

1. The schematic circuit diagram of a building.

The biaxially rocker key module VCC, GND 5V development board are connected, GND, X-axis output module, Y-axis output boards are connected to the analog pins A0, A1, Z-axis output module connected to the digital boards primer 2 feet.

Principle is shown below:

Experimental schematics

Physical connection is shown below:

Physical connection diagram

2. Create a new sketch, the following code replacement copies of the automatically generated code and save it.

 /*
 * JoyStick
 * 双轴按键摇杆
 */
#define pinX  A0
#define pinY  A1
#define pinK  2

int value = 0;

void setup()
{
  pinMode(pinK, INPUT);
  Serial.begin(9600);
}

void loop()
{
  value = analogRead(pinX);
  Serial.print("X: ");
  Serial.print(value);

  value = analogRead(pinY);
  Serial.print(" Y: ");
  Serial.print(value);

  value = digitalRead(pinK);
  Serial.print(" Z: ");
  Serial.println(value);
  
  delay(1000);
}

3. Development Board connector, and set the port number corresponding to the type of boards, for download.

Download

4. Experimental phenomenon

Open serial monitor, arranged to 9600 baud rate consistent with the program, twisting the joystick, the monitor will display the AD values ​​X, Y-axis corresponds to a voltage corresponding to.

Experimental phenomena

Since the ADC boards was 10-bit accuracy, the AD value is [0, 1023] between the theoretical X, Y-axis output value intermediate 512, but the potentiometer and structural differences, there is an origin offset value, some applications require calibration.

Focus on micro-channel public number: TonyCode
the Arduino learning exchange group: 868 283 450

More, I welcome the attention of the public number. Sweep the micro-channel to follow the Fanger Wei code:
Micro channel scan code added public number: TonyCode

Published 63 original articles · won praise 250 · Views 230,000 +

Guess you like

Origin blog.csdn.net/TonyIOT/article/details/103416103