Hi all,
I've been searching and banging my head against this issue with no progress, so I'm finally just going to reach out and ask the question to people who probably know more than me.
I've built this, and have struggling with it. It seems no matter what I do the potentiometers all, at the very least, effect each other. For example, if I move one pot the others move somewhat. In the worst case, they all mirror each other and move the same amount. In the searching I've done, I've seen people suggest doing a second analogRead and throwing out the first, but this has not helped (see the code below). I've double checked the pots and all the electrical connections. I've used multiple proMicros and I'm getting the same result. Any ideas?
#include <Joystick.h>
//Joystick Setup
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_JOYSTICK,
1, 0, // Button Count, Hat Switch Count
true, true, true, // X, Y, & Z Axis
false, false, false, // Rx, Ry, or No Rz
false, false, // Rudder but no throttle
false, false, false); // No accelerator, brake, or steering;
int leftPedal = 0;
int rightPedal = 0;
int rudderAxis_ = 0;
int lastButtonState[1];
int btnCount = 1;
int buttonPin[1] = {2};
void setup(){
// Initialize Button Pins
for (int i = 0; i < btnCount; i++)
{
pinMode(buttonPin[i], INPUT_PULLUP);
}
Joystick.begin(); //Starts joystick
}
void loop(){
checkButtons();
leftPedal = analogRead(A3);
leftPedal = analogRead(A3);
leftPedal = map(leftPedal,0,1023,0,255);
Joystick.setXAxis(leftPedal);
rightPedal = analogRead(A2);
rightPedal = analogRead(A2);
rightPedal = map(rightPedal,0,1023,0,255);
Joystick.setYAxis(rightPedal);
rudderAxis_ = analogRead(A1);
rudderAxis_ = analogRead(A1);
rudderAxis_ = map(rudderAxis_,0,1023,0,255);
Joystick.setZAxis(rudderAxis_);
delay(5);
}
void checkButtons(void) {
for (int i=0; i<btnCount; i++){
int currentButtonState = !digitalRead(buttonPin[i]);
// Change Joystick buttons only if the state has stateChanged
if (currentButtonState != lastButtonState[i]){
Joystick.setButton(i, currentButtonState);
lastButtonState[i] = currentButtonState;
}
}
}
PS. I had to add a button for SDL in Linux to see it as a joystick, so that's why that code is there.