Rudder code with potentiometer

Hi, I am trying to get joystick.h code working for a diy peddal project in the flight sim DCS. The serial monitor tells me I have values from 0-1023 and I have mapped these to 0 - 255. In the sim I move the potentiometer from right to left and get an decreasing value of left rudder. But going all the way to the right only makes the left rudder center and no more input can be made for the right rudder (f/a-18).

Can I remap the values to (0, 1023, -127, 127) and get equal input to the left and right rudders? I ask because I have read many code examples with the rudder being mapped to 0 -255.

Sure you can. Did you try? By the way, it should be (0, 1024, -128, 127) if the target variable is a char, or int8_t.

If a full rudder is 255, maybe you should (0, 1024, -256, 255)

It depends on what data type the result is declared as, in the library or your support code.

You should really post your entire sketch, to show the full context.

1 Like

No. You can't use negative values for PWM.
Consider 512 as being neutral. Then map involving the neutral point.

Why....??

OP never said anything about PWM. Also there is no code to reveal how the value is applied.

That's correct. I gambled and hoped we could jump a few posts ahead...

Hi, sorry for all the confusion, I thought maybe this was a very simple issue for newbies like me that just started learning to code. I dont have the code right now, will post it later today. Im using the example sketch for a joystick library (2.0), adjusting it to only take a single input ie rudder. The example didnt have a rudder but throttle code was present and is what I based my code on . A throttle normaly goes from zero to greater than zero so the behavior I described for my rudder is expected now that I think about it.

The goal of the project is:

  • using a single analogue potentiometer (dont know if there are digital ones) to create pedal (rudder) input that DCS World can handle. Therefore, PWM didnt seem right from what I understand.

Thanks for taking the time to reply :slight_smile:

Did you try map(value,0,1023,-127,127) or whatever?

It isn't your use-case, but I've used symmetric PWM like this:

  out = map(value,0,1023,-255,255);
  digitalWrite(dirPin, out > 0 ? HIGH : LOW);
  analogWrite(pwmPin, out > 0 ? out : -out);

Ok, I adjusted the mapping to (0, 1023, -X, +X) and can read the expected values in the arduino serial monitor. I tried several different X values with expected results. Have not tried in game though, no time.

Many thanks to all your great comments. My issue is not new, I’ve read several posts with similar issues but it really helped to get direct feedback from the community. Take care all!

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