Arkadaşlar direksiyon seti yapmak istiyorum. Hangi parçalar gerek?
Potansiyometre ardunio leonardo ile yapabilirsin ben yaptım
Abim yazılım elektronik okuyor. Onunla konuştum yapabileceğimizi söyledi.
C++ bilsen yeter ya da şu kütüpaneyi Arduino IDE'ye ekle
https://github.com/MHeironimus/ArduinoJoystickLibrary/archive/version-2.0.zip
Kütüpaneyi eksiz açtıktan sonnra eksiz/kütüphane ekle/.zip kütüphanesi ekle indirdiğin dosyayı seç.
Adam meketronik mühedisi bu arada.
Potansiyometreyi A0 pinine bağla .
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 = 25; // 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;
// Apply deadzone to avoid registering minor movements
if (abs(adjustedValue) <= deadzone) {
adjustedValue = 0;
}
Joystick.setXAxis(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)
}