Rehber Arduino Leonardo ile FFB'siz direksiyon seti yapımı

Uyarı: Bunu sadece Arduino Leonardo -- Pro Micro ile yapabilirsiniz.
Bugün size Arduino'nun Firmware'ını bozmadan direksiyon seti yapmayı göstereceğim. Devre şemamız:
Kullandığım platformda leonardo olmadığı için Uno kullandım.

Malzemeler :
Çok turlu potansiyometre .
Arduino Leonardo.


1719057142934.png


Arduino IDE'yi yüklüyoruz: Software
En son sürümü en üstteki seçenekle indiriyoruz.
Dosyayı açıp izin ver veya Allow ( İngilizce izin ver demek. ) Seçeneğine tıklıyoruz.
Standart İleri İleri Taktiğini uyguluyoruz. : )
Code butonuna tıklayarak download ZIP seçeneğini tıklıyoruz: GitHub - MHeironimus/ArduinoJoystickLibrary: An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
Arduino IDE'yi açıyoruz.
Eksiz > Kütüphane ekle >.ZIP kütüphanesi ekle ye tıklayıp indirdiğimiz dosyayı seçiyoruz.
Dosya > Yeni Eksiz"e tıklayarak gelen kodların hepsini Ctrl + A ile seçip silerek bu kodları kopyalayıp oraya yapıştırıyoruz.

Kodlar:

Kod:
#include <Joystick.h>
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD, 2, 8); // Create Joystick object
int steeringPin = A0; // Analog pin for potentiometer
const int centerValue = 512; // Center value of potentiometer (adjust if needed)
const int deadzone = 28;      // Deadzone to avoid registering minor movements
int button1Pin = 2; // Digital pin for button 1 (optional)
int button2Pin = 3; // Digital pin for button 2 (optional)
// ... Add more button pins if needed
void setup() {
  Joystick.begin();
  pinMode(steeringPin, INPUT);
  pinMode(button1Pin, INPUT_PULLUP); // Assuming button 1 has pull-up resistor
  pinMode(button2Pin, INPUT_PULLUP); // Assuming button 2 has pull-up resistor
  // ... Set other button pin modes if needed
}
void loop() {
  int steeringValue = analogRead(steeringPin);
  int adjustedValue = steeringValue; // Map potentiometer range to joystick axis range
  // Apply deadzone to avoid registering minor movements
  if (abs(adjustedValue) <= deadzone) {
    adjustedValue = 0;
  }
  Joystick.setRudder(adjustedValue);
  // Read and handle button presses (optional)
  int button1State = digitalRead(button1Pin);
  int button2State = digitalRead(button2Pin);
  // ... Read other button states if needed
  if (button1State == LOW) {
    // Button 1 pressed, perform a specific action
  }
  if (button2State == LOW) {
    // Button 2 pressed, perform a specific action
  }
  // ... Add code for other button functionality
  Joystick.sendState(); // Send joystick data to the computer
  delay(10);             // Optional debounce delay for buttons (adjust if needed)
}
 
Son düzenleme:

Technopat Haberler

Yeni konular

Geri
Yukarı