Hello, My X axis work fine but the Y axis is dead. on window game controller the little cross moves left to right fine, but wont move up and down. Just jumps a little bit and freezes. Both my encoders test fine. I paste my code here. My apologies, please tell me if there is another way to post code.
#include <Bounce2.h>
#include <Joystick.h>
#include <Encoder.h>
//#include <PluggableUSB.h>
// or
//#include <USB-MIDI.h>
// Define button pins
const int buttonAPin = 8;
const int buttonBPin = 9;
const int joystickXPinA = 2;
const int joystickXPinB = 3;
const int joystickYPinA = 4;
const int joystickYPinB = 5;
// Define the joystick object
Joystick_ Joystick;
// Define bounce objects to handle button debouncing
Bounce buttonABounce = Bounce(buttonAPin, 10);
Bounce buttonBBounce = Bounce(buttonBPin, 10);
//--------------------------------------------------
// Define the two encoder pins
const int encoder1PinA = 2;
const int encoder1PinB = 3;
const int encoder2PinA = 4;
const int encoder2PinB = 5;
// Create instances of the Encoder class
Encoder encoder1(encoder1PinA, encoder1PinB);
Encoder encoder2(encoder2PinA, encoder2PinB);
//-------------------------------------------------------
void setup() {
// Initialize the joystick library
Joystick.begin();
// Set button pins as inputs with internal pull-up resistors
pinMode(buttonAPin, INPUT_PULLUP);
pinMode(buttonBPin, INPUT_PULLUP);
}
void loop() {
// Update the joystick axes
int joystickX = digitalRead(joystickXPinA);
//int joystickX = digitalRead(joystickXPinB);
int joystickY = digitalRead(joystickYPinA);
//--------------------------------------------------
// Read encoder positions
int encoder1Value = encoder1.read();
int encoder2Value = encoder2.read();
//----------------------------------------------------
// Map joystick values to the joystick range (0 to 1023) to match HID joystick format
// Map encoder values to the joystick range (0 to 1023) to match HID joystick format
joystickX = map(encoder1Value, 0, 1023, 0, 1023);
joystickY = map(encoder2Value, 0, 1023, 0, 1023);
//--------------------------------------------------------------------------------------
// Print the values to the Serial Monitor
Serial.print("Encoder 1: ");
Serial.print(encoder1Value);
Serial.print("\tEncoder 2: ");
Serial.println(encoder2Value);
delay(100); // Adjust delay as needed
//-----------------------------------------------------------------------------------
// Update the joystick position
Joystick.setXAxis(joystickX);
Joystick.setYAxis(joystickY);
//------------------------------------------------------------
// Read button states with debouncing
buttonABounce.update();
buttonBBounce.update();
// Check if buttons are pressed and send joystick button states
if (buttonABounce.fell()) {
Joystick.setButton(1, 1);
} else if (buttonABounce.rose()) {
Joystick.setButton(1, 0);
}
if (buttonBBounce.fell()) {
Joystick.setButton(2, 1);
} else if (buttonBBounce.rose()) {
Joystick.setButton(2, 0);
}
// Add more buttons and code for additional features as needed
// A small delay to avoid sending data too quickly
delay(10);
}
