Jump to content

Mapping a pot value


Sting57

Recommended Posts

Hi all, I am using FP DCS Bios for my cockpit and needing a bit of help for mapping the pot values on my Console and instrument lighting pots  The range on the pots is approximately 1500 to 65000 (according to BORT).    This means that because the lower number is not zero, the backlighting is always on.   I was hoping to use the map() function like this.

void onConsolesDimmerChange(unsigned int newValue) {
        if (newValue < 1999) {
      ConsolesIntensitySwitch = map(newValue, 0, 1999, 0 , 0);  //slower kick-in to match sim
    }
    
    else {
      ConsolesIntensitySwitch = map(newValue, 2000, 65535, 0 , 180); //output capped to lower max brightness
    }
    analogRead(A0);
}
DcsBios::IntegerBuffer consolesDimmerBuffer(0x7544, 0xffff, 0, onConsolesDimmerChange);

 

This way DCS would not turn the lights on until my pot had passed 2000.

However it is not working.  The pot is connected to pit AO on a MEGA.  I have used the map() function with AnalogWrite however never with AnalogRead (I'm not sure if it is the correction function to use.

With the code, DCS does not read/see the value of the pot.

This of course works

DcsBios::Potentiometer consolesDimmer("CONSOLES_DIMMER", A0);

Any thoughts?

 

 


Edited by Sting57

Win11 64bit, AMD Ryzen 58003DX, GeForce 3070 8GB, 2TB SSD, 64GB DDR4 RAM at 3200MHz _ full 1:1 FA-18C Cockpit https://www.youtube.com/@TheHornetProject

Link to comment
Share on other sites

15 hours ago, lesthegrngo said:

It may be the type of potentiometer, some are exponential rather than linear - are you able to tell us the potentiometer type?

Cheers

 

Les

I believe they are all linear.

14 hours ago, No1sonuk said:

You're using the functions wrong.

Try analogRead in a main loop function, then use SendDcsBiosMessage to send the numbers to DCS.

Thanks, unfortunately i am not a coder so quite unsure what any of that means.  I will keep playing around.

 

Thanks

Win11 64bit, AMD Ryzen 58003DX, GeForce 3070 8GB, 2TB SSD, 64GB DDR4 RAM at 3200MHz _ full 1:1 FA-18C Cockpit https://www.youtube.com/@TheHornetProject

Link to comment
Share on other sites

So what I do for the A-10C is reading the value of the linear 10kOhm pot at the Lighting Control Panel (analogue input A0) and put the value directly to DcsBios for the console lighting signal, like

DcsBios::Potentiometer lcpConsole("LCP_CONSOLE", A0);

 

That value may be read back from DcsBios (here: onLcpConsoleChange) and than mapped (to e.g. a PWM value) to bring it to a dimmable backlight LED strip of a panel. That code may be used for several panels. (In my case a division of the read back value by 256 is more efficient than the map function as PWM signals of a Nano or Mega are in the range of 0 to 255.)

// ---------- DCS content here below ----------
// For Console Lights: definition  of the Output Pin (PWM)
    const int ConsoleLightsPin = 3;        // use PWM PIN for Console Lights (via MOSFET)

// For Console Lights: definition of the Output as PWM signal
    void onLcpConsoleChange(unsigned int newValue) {  // Min. Value 0 - Max. Value: 65535
    analogWrite(ConsoleLightsPin, (newValue/256));     // writes as PWM (0 - 255)
    }
    DcsBios::IntegerBuffer lcpConsoleBuffer(0x1150, 0xffff, 0, onLcpConsoleChange);

 

 

Regards, Vinc


Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

First-off:  Try this to get the end values the Arduino sees when it does the A/D conversion:
https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogReadSerial

 

Then try this:

DcsBios::Potentiometer consolesDimmer("CONSOLES_DIMMER", A0, false, min_value, max_value);

Yup.  Input range mapping was added to the function last year sometime.  You'll need to make sure you have the latest Arduino library

The "false" means "don't reverse the operation" - change it to "true" if your pot goes the wrong way and you don't want to remap it in-game or rewire it.
The function works without those last 3 parameters because defaults are set. The defaults are false, min_value = 0 , max_value = 1023

The DCS-BIOS code then automatically maps like this for non-reversed:
State = map(analogRead(pin), min_value, max_value, 0, 65535);

And like this for reversed:
State = map(analogRead(pin), min_value, max_value, 65535, 0);


You could also do this if you just need to reverse the pot, but not change the min and max:

DcsBios::Potentiometer consolesDimmer("CONSOLES_DIMMER", A0, true);

 

  • Like 1
Link to comment
Share on other sites

3 hours ago, Vinc_Vega said:

So what I do for the A-10C is reading the value of the linear 10kOhm pot at the Lighting Control Panel (analogue input A0) and put the value directly to DcsBios for the console lighting signal, like

DcsBios::Potentiometer lcpConsole("LCP_CONSOLE", A0);

 

That value may be read back from DcsBios (here: onLcpConsoleChange) and than mapped (to e.g. a PWM value) to bring it to a dimmable backlight LED strip of a panel. That code may be used for several panels. (In my case a division of the read back value by 256 is more efficient than the map function as PWM signals of a Nano or Mega are in the range of 0 to 255.)

// ---------- DCS content here below ----------
// For Console Lights: definition  of the Output Pin (PWM)
    const int ConsoleLightsPin = 3;        // use PWM PIN for Console Lights (via MOSFET)

// For Console Lights: definition of the Output as PWM signal
    void onLcpConsoleChange(unsigned int newValue) {  // Min. Value 0 - Max. Value: 65535
    analogWrite(ConsoleLightsPin, (newValue/256));     // writes as PWM (0 - 255)
    }
    DcsBios::IntegerBuffer lcpConsoleBuffer(0x1150, 0xffff, 0, onLcpConsoleChange);

 

 

Regards, Vinc

 

Thanks Vinc,  I do this for the backlighting out put.  With my own backlighting I use the map() function to not output until the pot turns a certain distance.  My issue is the other panels, like WinWing,throttle.

2 hours ago, No1sonuk said:

First-off:  Try this to get the end values the Arduino sees when it does the A/D conversion:
https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogReadSerial

 

Then try this:

DcsBios::Potentiometer consolesDimmer("CONSOLES_DIMMER", A0, false, min_value, max_value);

Yup.  Input range mapping was added to the function last year sometime.  You'll need to make sure you have the latest Arduino library

The "false" means "don't reverse the operation" - change it to "true" if your pot goes the wrong way and you don't want to remap it in-game or rewire it.
The function works without those last 3 parameters because defaults are set. The defaults are false, min_value = 0 , max_value = 1023

The DCS-BIOS code then automatically maps like this for non-reversed:
State = map(analogRead(pin), min_value, max_value, 0, 65535);

And like this for reversed:
State = map(analogRead(pin), min_value, max_value, 65535, 0);


You could also do this if you just need to reverse the pot, but not change the min and max:

DcsBios::Potentiometer consolesDimmer("CONSOLES_DIMMER", A0, true);

 

 

Ohh that looks nice and simple, will try as soon as i get home.

 

Thanks!

Win11 64bit, AMD Ryzen 58003DX, GeForce 3070 8GB, 2TB SSD, 64GB DDR4 RAM at 3200MHz _ full 1:1 FA-18C Cockpit https://www.youtube.com/@TheHornetProject

Link to comment
Share on other sites

Ok just wanted to say thanks for the all help you guys provided.  While it did not work I am very appreciative.

With not having any luck with a software solution I decide to look at the hardware with a view to replacing the pots.   Using the AnalogReadSerial code mentioned above i could see that neither pot was returning to zero.  I am using a shared ground for the entire lighting panel, which as three pots and two toggle switches.  During my testing i moved the ground wire on the arduino to another slot and boom, problem solved.  Immediately after i moved the connection the pots returned to zero.

 

So the issue is solved,  for now.  I have no idea if the issue will return cause when I reconnected to the original slot it worked as well.   So hopefully it was just a bad connection.

 

 

Win11 64bit, AMD Ryzen 58003DX, GeForce 3070 8GB, 2TB SSD, 64GB DDR4 RAM at 3200MHz _ full 1:1 FA-18C Cockpit https://www.youtube.com/@TheHornetProject

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...