Codey OnlineBiblioteca de componentes Arduino y ESP32 › Joystick module
Joystick module
Entrada y botones

Joystick module

Este módulo joystick ofrece dos salidas analógicas de posición para los ejes X e Y, además de un pulsador digital en SW. Normalmente se conecta a alimentación y masa, con VRX y VRY leídos por entradas analógicas y SW leído como entrada digital.

Ancho: 41.2 mm

Pinout — Joystick module

Pin Señal Descripción
GND ground Ground reference for the joystick module and pushbutton circuit
VCC power Power supply input for the joystick potentiometers, typically 5V or 3.3V
VRX analog Analog X-axis output from the joystick potentiometer
VRY analog Analog Y-axis output from the joystick potentiometer
SW digital Digital pushbutton output from pressing the joystick, commonly active-low

Esquema de cableado de ejemplo — Joystick module

Desde Hasta Cable
board:GND x1:GND black
board:5V x1:VCC red
board:A0 x1:VRX green
board:A1 x1:VRY blue
board:D2 x1:SW yellow

Código Arduino de ejemplo — Joystick module

Este ejemplo se escribió y verificó por compilación para arduino-uno. Codey Online lo adapta a cualquier otra placa compatible.

// Joystick module example for Arduino Uno
// Reads X/Y analog positions and the built-in pushbutton switch.

const int PIN_VRX = A0;
const int PIN_VRY = A1;
const int PIN_SW  = 2;

void setup() {
  pinMode(PIN_SW, INPUT_PULLUP); // SW is commonly active-low
  Serial.begin(9600);
  while (!Serial) {
    ;
  }
  Serial.println("Joystick module demo started");
  Serial.println("Format: X=<0-1023> Y=<0-1023> SW=<PRESSED/RELEASED>");
}

void loop() {
  int xValue = analogRead(PIN_VRX);
  int yValue = analogRead(PIN_VRY);
  bool pressed = (digitalRead(PIN_SW) == LOW);

  Serial.print("X=");
  Serial.print(xValue);
  Serial.print("  Y=");
  Serial.print(yValue);
  Serial.print("  SW=");
  Serial.println(pressed ? "PRESSED" : "RELEASED");

  delay(200);
}

Componentes relacionados

12V DC power supply

12V DC power supply

5V DC

5V DC

Drukknop

Drukknop

HX711 Load Cell Amplifier

HX711 Load Cell Amplifier

Crea tu proyecto de Arduino o ESP32 con IA

Describe lo que quieres construir. Codey Online escribe el codigo, dibuja el esquema de conexiones, lo compila y graba tu placa directamente desde el navegador.

Empieza gratis