Hello,
I have made a simple analog joystick with Arduino Pro Micro using this Joystick library: GitHub - MHeironimus/ArduinoJoystickLibrary: An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
The problem is that I need somehow to do electronic trims instead of using analog ones. I have searched a lot but with no luck finding anything like this. Is it even possible to do so? Have anyone tried doing this kind of trims? Thanks for any help!
The code:
#include <Joystick.h>
int RxAxis_ = 0;
int RyAxis_ = 0;
int Rudder_ = 0;
const bool initAutoSendState = true;
void setup()
{
pinMode(2, INPUT_PULLUP);
Joystick.begin();
}
const int pinToButtonMap = 2;
int lastButtonState[1] = {0};
void loop(){
for (int index = 0; index < 1; index++)
{
int currentButtonState = !digitalRead(index + pinToButtonMap);
if (currentButtonState != lastButtonState[index])
{
Joystick.setButton(index, currentButtonState);
lastButtonState[index] = currentButtonState;
}
}
RxAxis_ = analogRead(A1);
RxAxis_ = map(RxAxis_,0,1023,0,255);
Joystick.setXAxisRotation(RxAxis_);
RyAxis_ = analogRead(A0);
RyAxis_ = map(RyAxis_,0,1023,0,255);
Joystick.setYAxisRotation(RyAxis_);
Rudder_ = analogRead(A2);
Rudder_ = map(Rudder_,1023,0,255,0);
Joystick.setRudder(Rudder_);
delay (50);
}