[SOLVED]Arcade trackball to usb mouse help

Okay, so I did as you stated and modified the code and got everything to work. How would I go about making the trackball a lot less sensitive and more like the joystick? I can already tell by my test that I will need to somehow make a dead zone so the computer will realize that if I'm rolling the ball Up it actually goes up and ignores the little fidgets from side to side for instance. Also I'm looking for a way to have the acceleration taken into account. Like the faster I roll it the more the joystick registers in that direction. Like when you push just a bit on an actual analog joystick it goes a little bit in that direction. It is all working how you stated it would though, so many thanks to you for all your help thus far and I gave you some good karma for putting up with me though all this. I know I can be a bit annoying with simple to answer questions and all. I'm new to this but am learning a lot from you and I thank you for that as well.

Furthermore, how would I go about adding one more actual rotary encoder to the sketch as the Z axis. I tried doing it and all I get is it fidgeting back and forth in the properties window. I took the X axis and copied it and changed all the values that had "X" and changed them to Z and reduced the numbers to 63 and -63 but that didn't seem to work the way I hoped. Also if you could get this working, is there a way to have it accelerate the faster I turn the knob is that direction? I did this on pins 4 & 5.

I'm also having trouble adding buttons above pin ten. I'm getting the same result as last time where some of the buttons are locked down like they are being pressed even though they aren't. I'll post my code.

EDIT: I went ahead and installed some 1K pullup resistors on pins 4 & 5 but that didn't seem to fix the problem. I was reading on a different forum that sometimes the rotary encoder needs theses resistors to operate properly, however that didn't seem to do the trick :frowning: Also should I be hooking the centre pin of the encoder to GND or 5VDC? I currently have it hooked to GND.

#include <Encoder.h>
#include <Joystick.h>

// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 6;
  
Encoder axisX(0, 1);
Encoder axisY(2, 3);
Encoder axisZ(4, 5);

void setup() {
  // Initialize Buttons

  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
  pinMode(19, INPUT_PULLUP);
  pinMode(20, INPUT_PULLUP);
  pinMode(21, INPUT_PULLUP);
  
  
  // Initialize Joystick Library
  Joystick.begin(false);
}

void loop() {
  Joystick.setXAxis(0);               // Center joystick X
  int newX = axisX.read();            // Read X encoder
  if (newX > 0)                       // Has the value increased since last read
  {
    Joystick.setXAxis(127);           // Set joystick X hard over to right
    axisX.write(0);                   // Zero encoder count for next time
 }
  if (newX < 0)                       // Has encoder decreased since last read
  {
    Joystick.setXAxis(-127);          // Set joystick hard left
    axisX.write(0);                   // Zero encoder count
  }
  
  Joystick.setYAxis(0);               // Center joystick Y
  int newY = axisY.read();
  if (newY > 0) 
  {
    Joystick.setYAxis(127);
    axisY.write(0);
  }
  if (newY < 0) 
  {
    Joystick.setYAxis(-127);
    axisY.write(0);
  }

  Joystick.setZAxis(0);               // Center joystick Z
  int newZ = axisZ.read();
  if (newZ > 0) 
  {
    Joystick.setZAxis(63);
    delay(50);
    axisZ.write(0);
  }
  if (newZ < 0) 
  {
    Joystick.setZAxis(-63);
    delay(50);
    axisZ.write(0);
  }

  // Read button pin values
  for (byte index = 0; index < 12; index++)
  {
    byte currentButtonState = !digitalRead(index + pinToButtonMap); // Read button state
    Joystick.setButton(index, currentButtonState);                  // Set state in joystick
  }

  Joystick.sendState();               // Send the joystick data
  delay(50);                          // Wait a bit
}