Jump to content

DCS-Bios and Potentiometers


jerry262

Recommended Posts

I'm hoping someone can help me correct a mistake I've made. I designed a PC board for a UFC to run DCS-Bios using a shield which I also designed so a simple 40 pin cable connects the UFC to the Arduino. The Comm Volume knobs are obviously potentiometers. All is well except that I'm an idiot and I hardwired the Comm2 vol pot backwards. It works but I have to turn it the wrong way. Is it possible to reverse the functionality through DCS-Bios so that I don't have to re-design and re-make either of the PC boards.

 

Thanks

Link to comment
Share on other sites

I was about to say "switch the wires over" until I read the last part. ;)

 

To do it in software:

What you can do is take the value you get from the pot and subtract it from the maximum value you can have.

 

For example:

Max value = 100

Measured value = 25

new value = 100-25 = 75

 

Measured value = 75

new value = 100-75 = 25

 

OR

You can use the "map" command, like this:

 

newvalue = map( measured, 1, 100, 100, 1);

 

Also, if your code already uses a map command to scale your pot data before sending it to DCS-Bios, switching the last 2 numbers will reverse the output,

 

e.g.

newvalue = map( measured, 0, 100, 0, 200);

1 = 2, 2 = 4, 3 = 6, and so on.

 

To reverse, switch the second zero and 200:

 

newvalue = map( measured, 0, 100, 200, 0);

1 = 198, 2 = 196, 3 = 194, and so on.

Link to comment
Share on other sites

  • 2 weeks later...

Thank you so much for your help. I'm really new to DCS Bios and arduino programming for that matter. I have some coding background and understand code logic but I don't yet understand how to implement code into the various inputs. So far all I've managed is the basic calls like (DcsBios:: PotentiometerEWMA<5, 128, 5> ufcBrt("UFC_BRT", PIN);). I need to find someone else's code and study it so I can better understand the syntax and and how the DCS Bios interacts with the arduino code.

Thanks again for your help

Link to comment
Share on other sites

Have a look at this.

This code is a test program I wrote that displays the A-10 CMS data on an I2C LCD display, and includes a test setup of using neopixels to respond to one of the A-10 in-game backlight brightness controls.

/*
Tell DCS-BIOS to use a serial connection and use interrupt-driven
communication. The main program will be interrupted to prioritize
processing incoming data.

This should work on any Arduino that has an ATMega328 controller
(Uno, Pro Mini, many others).
*/

// This code was written to test combining some functions of the CMS panel and
// addressable LED backlighting
// It includes some code purely for use in testing, such as test value display


#define DCSBIOS_IRQ_SERIAL

// #include <Servo.h>

#include <FastLED.h>

#include <Wire.h>
/*
I2C connections:
Board I2C / TWI pins
Uno, Nano A4 (SDA), A5 (SCL)
Mega2560 20 (SDA), 21 (SCL)
Leonardo 2 (SDA), 3 (SCL)
Due 20 (SDA), 21 (SCL), SDA1, SCL1
*/

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display


#include "DcsBios.h"


// Some parameters for the addressable backlight LEDs

#define BACKLIGHTPIN 9 // Which pin on the Arduino is connected to the NeoPixels?
#define NUMPIXELS 12 // How many NeoPixels are attached to the Arduino?

uint8_t backlightBrightness = 64; // initial value - will be reset in brightness function later (255 max)

CRGB BacklightLEDs[NUMPIXELS]; // Memory array for the fastLED function


// Some extra bits for testing
DcsBios::LED masterCaution(0x1012, 0x0800, 13); // Master caution light
DcsBios::Switch2Pos ufcMasterCaution("UFC_MASTER_CAUTION", 10); // Master caution reset



// This section determines which control the backlight LEDs respond to
void onLcpConsoleChange(unsigned int newValue) {

backlightBrightness = map(newValue,0, 65535, 0, 255); // Change 16-bit input to 8-bit for FastLED brightness function

// For test purposes (as I'm using a 4-line display for testing)
lcd.setCursor(0,3); // set cursor position (column,line) starting at 0
lcd.print("Pnl BL Brt ctrl ");
lcd.print(backlightBrightness); // Control position
lcd.print(" "); // Trailing spaces to clear the line
// End of test display

LEDbacklight(backlightBrightness); // Run the lighting routine

}
DcsBios::IntegerBuffer lcpConsoleBuffer(0x1150, 0xffff, 0, onLcpConsoleChange);

// End of backlight control section

// This section reads the CMS display strings and sends them to the LCD

void onCmsp1Change(char* newValue) {
lcd.setCursor(0,0); // set cursor position (column,line) starting at 0
lcd.print(newValue); // Write the line to the display
}
DcsBios::StringBuffer<19> cmsp1Buffer(0x1000, onCmsp1Change);

void onCmsp2Change(char* newValue) {
lcd.setCursor(0,1); // set cursor position (column,line) starting at 0
lcd.print(newValue); // Write the line to the display
}
DcsBios::StringBuffer<19> cmsp2Buffer(0x1014, onCmsp2Change);

// End of CMS display string section

// This function checks if the power is on to enable the backlight brightness control to work
// Currently using the Angle of Attack gauge power flag as it changes state with the lighting power

bool power_is_off; // Power on/off flag

void onAoaPwroffChange(bool newValue) {
power_is_off = newValue;

// For test purposes (as I'm using a 4-line display for testing)
lcd.setCursor(0,2); // set cursor position (column,line) starting at 0
lcd.print("AoA power flag ");
lcd.print(power_is_off); // flag value
lcd.print(" "); // Trailing spaces to clear the line
// End of test display

LEDbacklight(backlightBrightness); // Run the lighting routine

}
DcsBios::IntegerBuffer aoaPwroffBuffer(0x1076, 0xffff, 0, onAoaPwroffChange);
// End of backlight enable section

// Backlight brightness and on/off output
// This was made separate to allow the power on/off setup to work properly

void LEDbacklight(unsigned int newValue) { // LED backlight brightness control

if (power_is_off == false){ // check if power is on
FastLED.setBrightness(newValue); // Set the new level
FastLED.show(); // Send it to the LEDs
}
else {
FastLED.setBrightness(0); // Set the LEDs off
FastLED.show(); // Send it to the LEDs
}

}
// End of backlight brightness and on/off output

void setup() {
DcsBios::setup();

//I2C LCD initialisation
lcd.init(); // initialize the lcd
lcd.backlight(); // Trun on the LCD backlight
lcd.setCursor(0,0); // set LCD cursor position (column,line) starting at 0
lcd.print("Display online");
lcd.setCursor(0,1); // set LCD cursor position (column,line) starting at 0
lcd.print("Awaiting DCS");

// Backlight LED initialisation
FastLED.addLeds<NEOPIXEL, BACKLIGHTPIN>(BacklightLEDs, NUMPIXELS); // Set up LED strip parameters

FastLED.setBrightness(backlightBrightness); // Set strip initial master brightness

fill_solid( BacklightLEDs, NUMPIXELS, CRGB::Green); // Fill strip with green - CRGB(0,255,0) also works

BacklightLEDs[0] = CRGB::Red; // Set 1st led as red - because why not?

FastLED.show(); // Send LED changes to the strip

}

void loop() {
DcsBios::loop();

}

I hope that's of some use.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  • 3 months later...

Hello!

I using original MiG 21 parts to build my home cockpit, and i now trying to adjust the nosecone knob whitch is basicly a potentiometer. I wired in a test board and make this video:

As you see the range of the needle is not quiet match on the digital version, and i wanted to adjust the offset and the power of the potentiometer. I using the basic parameters.

DcsBios::PotentiometerEWMA<5, 128, 5> coneAdj("CONE_ADJ", A0);

As i see the 5, 128, 5 parameters are just for to avoid noise in the analog input.

Thanks!

Apoth


Edited by Apoth
Link to comment
Share on other sites

  • Recently Browsing   0 members

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