Παραγγελία έως τις 14:00 τις εργάσιμες = αποστολή την ίδια ημέρα 30 ημέρες δικαίωμα υπαναχώρησης Εγγύηση 1 έτους
← Πίσω στην επισκόπηση

Διάγραμμα σύνδεσης και παράδειγμα κώδικα

Έτσι συνδέεις το Μονάδα joystick σε ένα Arduino UNO ή ESP32, με ένα παράδειγμα sketch που μπορείς να ανεβάσεις αμέσως.

Μονάδα joystick διπλού άξονα με κουμπί πίεσης

Αυτό το παράδειγμα διαβάζει τις αναλογικές θέσεις των αξόνων X και Y μαζί με το ενσωματωμένο κουμπί πίεσης της μονάδας joystick. Μετακινήστε το stick ή πιέστε το προς τα κάτω για να δείτε σε πραγματικό χρόνο τις τιμές θέσης και την κατάσταση του κουμπιού στο Serial Monitor.

Διάγραμμα σύνδεσης: Μονάδα joystick σε ένα Arduino UNO
Διάγραμμα σύνδεσης · Κάνε κλικ για μεγέθυνση
Πίνακας σύνδεσης: Μονάδα joystick σε ένα Arduino UNO
Πίνακας σύνδεσης · Κάνε κλικ για μεγέθυνση
Dual_Axis_Joystick_Module_with_Pushbutto.ino · μεταγλωττισμένο και δοκιμασμένο
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : Dual-Axis Joystick Module with Pushbutton
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : Joystick module
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// Pin definitions
const int PIN_X = A0;
const int PIN_Y = A1;
const int PIN_SW = 2;

void setup() {
  // Enable internal pull-up resistor for the integrated pushbutton
  pinMode(PIN_SW, INPUT_PULLUP);
  
  Serial.begin(115200);
  Serial.println(F("Joystick Module Demo"));
  Serial.println(F("--------------------"));
}

void loop() {
  // Read analog values for X and Y axes (range: 0 - 1023)
  int xVal = analogRead(PIN_X);
  int yVal = analogRead(PIN_Y);
  
  // Button is active-low (reads LOW when pressed)
  bool isPressed = (digitalRead(PIN_SW) == LOW);

  // Print the results to Serial Monitor
  Serial.print(F("X: "));
  Serial.print(xVal);
  Serial.print(F(" | Y: "));
  Serial.print(yVal);
  Serial.print(F(" | Button: "));
  Serial.println(isPressed ? F("PRESSED") : F("RELEASED"));

  delay(150);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Επίδειξη αναλογικής μονάδας joystick ESP32

Αυτό το έργο διαβάζει τις θέσεις X και Y καθώς και την κατάσταση του ενσωματωμένου κουμπιού από μια αναλογική μονάδα joystick δύο αξόνων. Το ESP32 διαβάζει αναλογικές τάσεις μέσω των GPIO 34 και 35, και την κατάσταση του κουμπιού μέσω του GPIO 32. Ανοίξτε το Serial Monitor στα 115200 baud για να δείτε σε πραγματικό χρόνο τις συντεταγμένες του joystick και τα πατήματα του κουμπιού.

Διάγραμμα σύνδεσης: Μονάδα joystick σε ένα ESP32 DevKit V1
Διάγραμμα σύνδεσης · Κάνε κλικ για μεγέθυνση
Πίνακας σύνδεσης: Μονάδα joystick σε ένα ESP32 DevKit V1
Πίνακας σύνδεσης · Κάνε κλικ για μεγέθυνση
ESP32_Analog_Joystick_Module_Demo.ino · μεταγλωττισμένο και δοκιμασμένο
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : ESP32 Analog Joystick Module Demo
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : Joystick module
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// Pin definitions (using bare GPIO numbers for ESP32)
const int pinVRX = 34;
const int pinVRY = 35;
const int pinSW  = 32;

void setup() {
  Serial.begin(115200);
  
  // Configure push-button pin with internal pull-up
  pinMode(pinSW, INPUT_PULLUP);
}

void loop() {
  // Read analog values from joystick potentiometers (0 - 4095 on ESP32)
  int xVal = analogRead(pinVRX);
  int yVal = analogRead(pinVRY);
  
  // Read digital state of the integrated switch (LOW when pressed)
  bool isPressed = (digitalRead(pinSW) == LOW);

  // Print the readings to the Serial Monitor
  Serial.print("X: ");
  Serial.print(xVal);
  Serial.print(" | Y: ");
  Serial.print(yVal);
  Serial.print(" | Button: ");
  Serial.println(isPressed ? "PRESSED" : "RELEASED");

  delay(100);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Πρόσφατα προβεβλημένα

BBC Micro:bit V2.2

BBC Micro:bit V2.2

€ 19,95
Προβολή