Afternoon all - very new to this, but have been putting in the time to try and figure it out but have come full circle so hoping someone can help me understand what is going on.
A year of so ago I built a helicopter collective to be used in flight sims - just a couple of hall sensors and basic code - it's worked well and happy with it. I decided I wanted to add a few toggle switches and a couple of rotary switches. Each of the rotary switches have 6 positions, I didn't want to use up pins unnecessarily on the arduino so followed the advice on the web and used resistors to join the pins so changes in voltage out put could be detected and displayed in the monitor. All that works fine, tolerences are good and consistent.
So as it stands I have two bits of code, one for the collective itself, one for the test rotary switch - I'm at a loss on how to merge them. I use the joystick.h library and though it does most things, I can't see anyway of integrating the rotary switches, or 'maping' the output from each position of the toggle switch to a specific joystick button.
Another thing which is quite strange, in the sketch I have compiled, when I use the toggle switch it moves the 'X Rotation' bar in windows game controllers -so clearly I have done something completely wrong.....
So any help would be appreciated and gratefully recieved.
```cpp
#include <Joystick.h>
#define Collective A0
int rxAxis_ = 0;
#define Throttle A1
int Throttle_ = 0;
#define Rotary1 A5
int sensorPin = A5;
int sensorValue = 0;
int rotswitchNumber = 0;
Joystick_ Joystick(0x04, JOYSTICK_TYPE_JOYSTICK,
6, 0, // Button Count, Hat Switch Count
false, false, false, // X and Y, Z Axis
true, false, false, // Rx, Ry, or Rz
false, true, // rudder, throttle
false, false, false); // accelerator, brake, or steering
//const bool initAutoSendState = true;
void setup() {
Joystick.begin();
Serial.begin(9600);
}
void loop() {
Throttle_ = analogRead(Throttle) / 04;
Throttle_ = map(Throttle_, 0, 1023, 0, 255);
Joystick.setThrottle(Throttle_);
rxAxis_ = analogRead(Collective);
rxAxis_ = map(rxAxis_, 0, 1023, 0, 255);
Joystick.setRxAxis(rxAxis_);
// read the value from the sensor:
sensorValue = analogRead(Rotary1);
Serial.print("Value:");
Serial.println(sensorValue);
Serial.print("SwitchNumber:");
Serial.println(rotswitchNumber);
delay(1000); // delay in between reads for stability
if ((sensorValue >= 700) && (sensorValue <= 720)) {
rotswitchNumber = 1;
} else if ((sensorValue >= 740) && (sensorValue <= 760)) {
rotswitchNumber = 2;
} else if ((sensorValue >= 800) && (sensorValue <= 830)) {
rotswitchNumber = 3;
} else if ((sensorValue >= 850) && (sensorValue <= 880)) {
rotswitchNumber = 4;
} else if ((sensorValue >= 930) && (sensorValue <= 960)) {
rotswitchNumber = 5;
} else if ((sensorValue >= 1015) && (sensorValue <= 1023)) {
rotswitchNumber = 6;
}
Joystick.sendState();
delay(10);
}