I am using Joystick Library to make a HOTAS system for flight simulators. When I load the test program I can get all the simulated controller inputs to register in windows. I can also get the value from my slide potentiometer to read in the serial monitor. But it will not change the value of the input function i pass it to. my guess is its the wrong kind of integer but I don't know very much about int types. Joystick.setThrottle has an int32_t as a parameter. Windows reads the value of throttle at 49% when its connected.
What I have tried:
changing the range (the default is 0 to 1023 I want it to be 0 to 255)
changing the type of throttle_ to int, unsigned int, and int_32_t
changing initAutoSendState
using the pin number instead of the macro throttle passing throttle_ directly into Joystick.setThrottle without the updateThrottle function
I have some programming experience from my high school class so I just tried different approaches but I am new to Arduino.
#include "Joystick.h"
//define input pins
#define throttle A0
//include hid, type, button count, hat count, x axis, y axis, z axis, Rx axis, Ry axis, Rz axis, rudder, Throttle, Accelerator, Brake, Steering
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_JOYSTICK, 0, 0, false, false, false, false, false, false, false, true, false, false, false);
const bool initAutoSendState = true;
int32_t throttle_ = 0;
void updateThrottle (int32_t value)
{
Joystick.setThrottle(value);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(throttle, INPUT_PULLUP);
Joystick.setThrottleRange(0, 255);
}
void loop() {
// put your main code here, to run repeatedly:
throttle_ = analogRead(throttle);
throttle_ = map(throttle_, 0, 1023, 0, 255);
updateThrottle(throttle_);
Serial.print(throttle_);
Serial.print("\n");
}