Codey OnlineBibliothèque de composants Arduino & ESP32 › Joystick module
Joystick module
Entrée & boutons

Joystick module

Ce module joystick fournit deux sorties analogiques de position pour les axes X et Y, ainsi qu’un bouton-poussoir numérique sur SW. Il est généralement relié à l’alimentation et à la masse, avec VRX et VRY lus via des entrées analogiques et SW lu comme entrée numérique.

Largeur: 41.2 mm

Brochage — Joystick module

Broche Signal Description
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

Exemple de schéma de câblage — Joystick module

De Vers Fil
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

Exemple de code Arduino — Joystick module

Cet exemple a été écrit et vérifié à la compilation pour le arduino-uno. Codey Online l'adapte pour vous à toute autre carte prise en charge.

// 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);
}

Composants similaires

12V DC power supply

12V DC power supply

5V DC

5V DC

Drukknop

Drukknop

HX711 Load Cell Amplifier

HX711 Load Cell Amplifier

Construisez votre projet Arduino ou ESP32 avec l'IA

Décrivez ce que vous voulez créer. Codey Online écrit le code, dessine le schéma de câblage, le compile et flashe votre carte directement depuis le navigateur.

Commencez gratuitement