I can read 6 potentiometers and have the USB control panel in windows display their value.
This is the code that works:
//
// Controller for dials for a Flight Simulator
// using an Arduino Leonardo or Arduino Micro.
// based on code from
// Matthew Heironimus
//
//------------------------------------------------------------
#include "Joystick.h"
Joystick_ Joystick;
char potPins[] = {
A0,A1,A2,A3,A6,A7
};
byte potCount = 6;
int inputPot = 0;
void setup() {
Joystick.begin();
}
void loop() {
for (int thisPot = 0; thisPot < potCount; thisPot++) {
inputPot = analogRead(potPins[thisPot]);
switch (thisPot) {
case 0:
Joystick.setXAxis(inputPot);
break;
case 1:
Joystick.setYAxis(inputPot);
break;
case 2:
Joystick.setZAxis(inputPot);
break;
case 3:
Joystick.setRxAxis(inputPot);
break;
case 4:
Joystick.setRyAxis(inputPot);
break;
case 5:
Joystick.setRzAxis(inputPot);
break;
default:
break;
}//end switch
}//end for
}
I calibrated all 6 potentiometers in the USB control panel settings tab. The raw values range from 0 to 65535. In the calibration dialogs, each potentiometer smoothly moves the values.
However, in the Test tab of the Game Controller control panel the behavior of the X Axis and Y Axis are odd. The slightest rotation from the leftmost position rightwards results in a jump of the X Axis indicator to its midpoint of the excursion. It then moves smoothly to its rightmost limit. The potentiometer mapped to the Y Axis does the same thing. The slightest twist to the right and the indicator on the control panel jumps halfway down. From there it moves smoothly to the bottom.
The Z axis, X Rotation, Y Rotation, and Z Rotation all move smoothly in a linear fashion. However the X Axis and Y Axis behave oddly.
In the original sample code, the joystick library was initialized with a little more complexity like so:
/*
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_MULTI_AXIS, 32, 0,
true, true, false, false, false, false,
true, true, false, false, false);
*/
I dont know what that all means but am wondering if windows is expecting the X Axis and Y Axis to go from -32767 to +32767.
I tried changing the relevant lines for those pots to this
Joystick.begin();
Joystick.setXAxisRange(-32767,32767);
Joystick.setYAxisRange(-32767,32767);
}
void loop() {
for (int thisPot = 0; thisPot < potCount; thisPot++) {
inputPot = analogRead(potPins[thisPot]);
switch (thisPot) {
case 0:
Joystick.setXAxis(inputPot-32767);
break;
case 1:
Joystick.setYAxis(inputPot-32767);
break;
Now the X Axis and Y Axis raw values go from 0 to 1023 in the calibration window. Their movement in the calibration window is smooth and corresponds linearly with the twisting of the potentiometer.
In the test window their behavior is still irregular, the indicators jump to 50% with the slightest twist to the right while the remainder of the excursion is linear with the pot.
I know am missing something but need help seeing it.