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);
}