Hello
Im going to add a angle offset to my stick as it is in the real F16 with a 12 degree rotation offset so when i pull the stick a little back and left it will be like i am pulling straight back. I really have no clue how to do this and i have severe working memory issues so as soon as i look away from a text its pretty much gone so i need very clear and easy to follow examples.
If anyone could help me with this is would be most grateful.
//#include <AnalogSmooth.h>
#include <Joystick.h>
#include <Smoothed.h>
/*
For the true false flags, use this list. Its all in Joystick.h
bool includeXAxis = true,
bool includeYAxis = true,
bool includeZAxis = true,
bool includeRxAxis = true,
bool includeRyAxis = true,
bool includeRzAxis = true,
bool includeRudder = true,
bool includeThrottle = true,
bool includeAccelerator = true,
bool includeBrake = true,
bool includeSteering = true);
*/
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_MULTI_AXIS, 32, 0,
true, true, false, false, false, false,
true, true, false, false, false);
// Variable
#define YfAxisPin A0
#define YbAxisPin A1
#define XlAxisPin A2 // needed to reverse
#define XrAxisPin A3
// Add pins for the different ranges. Just using a variable for now.
// Max force from trigger height.
// Max force for y is about 8kg
// Max force for X left is about 8kg X right is about 6kg
// Max force in %
int YMaxforce = 100;
int XMaxforce = 100;
// add offset to X Y
int Offset = 0;
// Add smoothing for all axis
Smoothed <int> YfAxis;
Smoothed <int> YbAxis;
Smoothed <int> XlAxis;
Smoothed <int> XrAxis;
int SmoothValue = 30;
// init joystick libary
void setup() {
Joystick.begin();
Serial.begin(38400);
// Ranges are 1023 by default
Joystick.setYAxisRange(0, 2048);
Joystick.setXAxisRange(0, 2048);
// Begin smoothing.
YfAxis.begin(SMOOTHED_AVERAGE, SmoothValue);
YbAxis.begin(SMOOTHED_AVERAGE, SmoothValue);
XlAxis.begin(SMOOTHED_AVERAGE, SmoothValue);
XrAxis.begin(SMOOTHED_AVERAGE, SmoothValue);
}
void loop() {
// Read the value from the sensor
int YfAxisValue = analogRead(YfAxisPin);
int YbAxisValue = analogRead(YbAxisPin);
int XlAxisValue = analogRead(XlAxisPin);
int XrAxisValue = analogRead(XrAxisPin);
// Add the new value to both sensor value stores
YfAxis.add(YfAxisValue);
YbAxis.add(YbAxisValue);
XlAxis.add(XlAxisValue);
XrAxis.add(XrAxisValue);
// ******** Y Axis ***************
int YfAxisCValue = YfAxis.get();
int YbAxisCValue = YbAxis.get();
int YAxisfront = YbAxisCValue;
// remap Yaxisback
YbAxisCValue = map(YbAxisCValue, 1023, 0, 0, 1023);
int YcombinedValue = YfAxisCValue + YbAxisCValue;
// Set joystick Axis
Joystick.setYAxis(YcombinedValue + Offset);
// Serial.println (String("Yf:") + YfAxisCValue);
// Serial.println (String("Bf:") + YbAxisCValue);
// Serial.println (String("Y combined:") + YcombinedValue);
/* // rememnats from another stick, just use it to remember
if (throttleValue > 666) {
throttleValue = 670;
}
else if (throttleValue < 273) {
throttleValue = 270;
}
if (lastThrottleValue != throttleValue) {
Joystick.setThrottle(throttleValue);
lastThrottleValue = throttleValue;
}
delay(1);
*/
// ********* X axis **************
int XlAxisCValue = XlAxis.get();
int XrAxisCValue = XrAxis.get();
XrAxisCValue = map(XrAxisCValue, 1023, 0, 0, 1023);
int XcombinedValue = XlAxisCValue + XrAxisCValue;
// Set joystick Axis
Joystick.setXAxis(XcombinedValue + Offset);
// Serial.println (String("Xl:") + XlAxisCValue);
// Serial.println (String("Xr:") + XrAxisCValue);
// Serial.println (String("X combined:") + XcombinedValue);
// Serial.println (String("X:") + XAxisCValue);
/*
if (brake < 0 or brake < 8) {
brake = 0;
}
if (lastBrakeValue != brake) {
Joystick.setBrake(brake);
lastBrakeValue = brake;
}
delay(1);
*/
}