Arduino Joystick Electronic Trims

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);
}

You can add an offset to the RxAxis_ or RyAxis_ Eventually your library allows to define offsets?

Please say what you mean by these two terms you are using.

a7

I need to be more specific. I want to have trims with buttons which will move my joystick axis (x or y) center position to one or another way. The project that I am working on is gimbal camera which is controlled with joystick and when we have a drift we just trim it or sometimes use the trims for continuous movement of the gimbal. It is better and more precise to use buttons that gives commands to trim that positions than the mechanical potentiometer trimming.

Actually I do not know if it is possible, I have to do more research on that library or maybe try to find other similar libraries

You always can add something to your variables. Use buttons to change the variable value to add.

I am getting the idea, will try to do something like that, thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.