Help with Code, Arduio Pro Micro & Joystick.h library

Ok, so the goals for the project are to simply, have 10 bit resolution analogue input for gas, brakes and clutch for a set of custom pedals for sim racing. Lag is a concern, if its gona be a concern... but one problem at a time i guess.

I am using an Arduino Pro Micro and Joystick Library by Matthew Heironimus.

Here is the trouble. All the input seem to respond together. Adjust input on one, effectively does the same to them all. I have tested on multiple Pro Micros, as well as úsing different analogue Pins to get the same results. Can someone help me figure out why I am having problems, and how i can fix it.

Thanks.

Here is the code I'm using.

// Jens Arduino Pedals
// This car simulator pedals program have gas, brake and clutch to connect to usb port.
// No extra drives need to be installed in windows to get this to work.
//
// For more information how to connect and get this to work go too www.jensws.com/pedals
//
// NOTE: This file is for use with Arduino Leonardo and  Arduino Micro only.
//       Arduino Micro only.
//
// To get this program to work you need GPLv3 joystick libary from
// https://github.com/MHeironimus/ArduinoJoystickLibrary/tree/version-2.0
//
// by Jens Söderström jensws.com
// 2016-11-01
//--------------------------------------------------------------------


#include "Joystick.h"

//add the folowing from example code in DrivingControllerTest - works //
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, 
  JOYSTICK_TYPE_MULTI_AXIS, 4, 0,
  true , true, true, false, false, false,
  false, false, true, true, true);

    //           NOTES for above  https://github.com/MHeironimus/ArduinoJoystickLibrary
    // AXIS X Y Z
  //bool includeXAxis - Default: true - Indicates if the X Axis is available on the joystick.
  //bool includeYAxis - Default: true - Indicates if the Y Axis is available on the joystick.
  // bool includeZAxis - Default: true - Indicates if the Z Axis (in some situations this is the right X Axis) is available on the joystick.
    // Axis Rotation X Y Z
  //bool includeRxAxis - Default: true - Indicates if the X Axis Rotation (in some situations this is the right Y Axis) is available on the joystick.
  //bool includeRyAxis - Default: true - Indicates if the Y Axis Rotation is available on the joystick.
  //bool includeRzAxis - Default: true - Indicates if the Z Axis Rotation is available on the joystick.
    // Rudder, Throttle, Accel, Brake, Steerig
  //bool includeRudder - Default: true - Indicates if the Rudder is available on the joystick.
  //bool includeThrottle - Default: true - Indicates if the Throttle is available on the joystick.
  //bool includeAccelerator - Default: true - Indicates if the Accelerator is available on the joystick.
  //bool includeBrake - Default: true - Indicates if the Brake is available on the joystick.
  //bool includeSteering - Default: true - Indicates if the Steering is available on the joystick.


// Variable
int gas = A0;  //A0,A1,A2,A3,A4,A6,A8,A9,A10 are all available analog read pins //
int brake = A1; 
int clutch = A2;
int gasValue = 0;
int gasValuebyte = 0;
int brakeValue = 0;
int brakeValuebyte1 = 0;
int brakeValuebyte2 = 0;
int clutchValue = 0;
int clutchValuebyte1 = 0;
int clutchValuebyte2 = 0;

void setup() {
  Joystick.begin();
   //Serial.begin(38400);
}

void loop() {
  
  //  Gas = Joystick.setThrottle
  gasValue = analogRead(gas);
  if (gasValue >= 1) {
  gasValuebyte = gasValue /0 ;
   }
   else
   {
    gasValuebyte = 0 ;
   }
  Joystick.setThrottle(gasValuebyte);
  delay(1); 
  //Serial.println(gasValue);

  
  // Brake = Y axis = Joystick.setYAxis(brakeValuebyte2);//

  brakeValue = analogRead(brake);
  if (brakeValue >= 1) {
    brakeValuebyte1 = brakeValue / 4;
    brakeValuebyte2 = brakeValuebyte1 - 127;
  
   }
   else
   {
    brakeValuebyte2 = -127;
   }
  Joystick.setYAxis(brakeValuebyte2);
  delay(1); 
  
// Clutch = Joystick.setZAxis(clutchValuebyte2);//

  clutchValue = analogRead(clutch);
  if (clutchValue >= 1) {
  clutchValuebyte1 = clutchValue / 4;
  clutchValuebyte2 = clutchValuebyte1 - 127;
  
   }
   else
   {
    clutchValuebyte2 = -127;
   }
   Joystick.setZAxis(clutchValuebyte2);
  delay(1); 
}

your correct, that should be a 4. The code came from a guy (Jens) who made the same project, however he used an earlier version of the Joystick library. I have tried to earlier version of the library, but the resolution seems lower, and the results are still the same. That being said, I have simplified it, but still same results.

#include "Joystick.h"

 //              https://github.com/MHeironimus/ArduinoJoystickLibrary


Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, 
  JOYSTICK_TYPE_MULTI_AXIS, 4, 0,
  true , true, true, false, false, false,
  false, false, true, true, true);

int gas = A0;  
int brake = A1; 
int clutch = A2;
int gasValue = 0;
int brakeValue = 0;
int clutchValue = 0;


// init joystick libary
void setup() {
  Joystick.begin();

}

void loop() {
  
  gasValue = analogRead(gas);
  Joystick.setThrottle(gasValue);
  delay(1); 
  

  brakeValue = analogRead(brake);
  Joystick.setYAxis(brakeValue);
  delay(1); 
  

  clutchValue = analogRead(clutch);
  Joystick.setZAxis(clutchValue);
  delay(1); 
}

The micro is sitting on a breadboard,
Ground --> Jumpered to Ground Rails
Vcc --> jumpered to Positive rails
A0 --> Loose Jumper that I can connect to VCC to test
A1 --> Same as above
A2 --> Same as above

This is the test code, seems to work just fine.

// Program used to test the driving simulator functions on 
// the USB Joystick object on the Arduino Leonardo or 
// Arduino Micro.
//
// Matthew Heironimus
// 2016-05-29   Original version.
//------------------------------------------------------------

#include "Joystick.h"

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, 
  JOYSTICK_TYPE_MULTI_AXIS, 4, 0,
  false, false, false, false, false, false,
  false, false, true, true, true);

// Set to true to test "Auto Send" mode or false to test "Manual Send" mode.
//const bool testAutoSendMode = true;
const bool testAutoSendMode = false;

const unsigned long gcCycleDelta = 1000;
const unsigned long gcButtonDelta = 500;
const unsigned long gcAnalogDelta = 25;
unsigned long gNextTime = 0;
unsigned int gCurrentStep = 0;

void testSingleButtonPush(unsigned int button)
{
  if (button > 0)
  {
    Joystick.releaseButton(button - 1);
  }
  if (button < 4)
  {
    Joystick.pressButton(button);
  }
}

void testMultiButtonPush(unsigned int currentStep) 
{
  for (int button = 0; button < 4; button++)
  {
    if ((currentStep == 0) || (currentStep == 2))
    {
      if ((button % 2) == 0)
      {
        Joystick.pressButton(button);
      } else if (currentStep != 2)
      {
        Joystick.releaseButton(button);
      }
    } // if ((currentStep == 0) || (currentStep == 2))
    if ((currentStep == 1) || (currentStep == 2))
    {
      if ((button % 2) != 0)
      {
        Joystick.pressButton(button);
      } else if (currentStep != 2)
      {
        Joystick.releaseButton(button);
      }
    } // if ((currentStep == 1) || (currentStep == 2))
    if (currentStep == 3)
    {
      Joystick.releaseButton(button);
    } // if (currentStep == 3)
  } // for (int button = 0; button < 32; button++)
}

void testAcceleratorBrake(int value)
{
  Joystick.setAccelerator(value);
  Joystick.setBrake(260 - value);
}

void testSteering(int value)
{
  if (value < 300) {
    Joystick.setSteering(value);
  } else {
    Joystick.setSteering(600 - value);
  }
}

void setup() {

  Joystick.setAcceleratorRange(0, 260);
  Joystick.setBrakeRange(0, 260);
  Joystick.setSteeringRange(0, 300);
  
  if (testAutoSendMode)
  {
    Joystick.begin();
  }
  else
  {
    Joystick.begin(false);
  }
  
  pinMode(A0, INPUT_PULLUP);
  pinMode(13, OUTPUT);
}

void loop() {

  // System Disabled
  if (digitalRead(A0) != 0)
  {
    // Turn indicator light off.
    digitalWrite(13, 0);
    return;
  }

  // Turn indicator light on.
  digitalWrite(13, 1);
  
  if (millis() >= gNextTime)
  {
   
    if (gCurrentStep < 4)
    {
      gNextTime = millis() + gcButtonDelta;
      testSingleButtonPush(gCurrentStep);
    } 
    else if (gCurrentStep < 9)
    {
      gNextTime = millis() + gcButtonDelta;
      testMultiButtonPush(gCurrentStep - 5);
    }
    else if (gCurrentStep < (9 + 260))
    {
      gNextTime = millis() + gcAnalogDelta;
      testAcceleratorBrake(gCurrentStep - 9);
    }
    else if (gCurrentStep < (9 + 260 + 600))
    {
      gNextTime = millis() + gcAnalogDelta;
      testSteering(gCurrentStep - (9 + 260));
    }
    
    if (testAutoSendMode == false)
    {
      Joystick.sendState();
    }
    
    gCurrentStep++;
    if (gCurrentStep >= (9 + 260 + 600))
    {
      gNextTime = millis() + gcCycleDelta;
      gCurrentStep = 0;
    }
  }
}

Ugh....DUH. Thanks :o :o :o