Jump to content

-CRO- Dr. Death

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by -CRO- Dr. Death

  1. Yeah there are a few things I could do to cut down on the pins used, (button matrix, LED array, even rotary switch as an analog input). but I'm building this thing to be modular system, so redundant pins will be expected. One question I have about DCS Bios is; in a lot of the tutorial videos on youtube, they pretty much all use the 'connect-serial-port.cmd' program to hook up the panel to DCS. But mine connects fine through DCS Bios which starts up automatically and connects automatically. So what is the point of the 'connect-serial-port.cmd' program?
  2. Thanks for your input as well Vinc_Vega. Yeah mate I'm using PMW pins. Mega is a monster board, perfect for this application. I could probably even run future panels back to this board. I'm running out of PWM pins, but have plenty of Analog and Digital pins left Cheers
  3. You Sir are an absolute genius. Thank you so much, I have literally spent like 5 hours trying to work this out. I owe you a beer. Here is my final code with all LED's working correctly if your interested: // AH64 Left Hand Power Console // Special Thanks to No1sonuk // Arduino Mega 2560 // 18/02/2024 /* WIP - Need to write new code for- Servo Output/Friction Lever. Servo pin=D9 Add LED Brightness sourced from Pilot Signal Light. WIP - */ #define DCSBIOS_IRQ_SERIAL #include <Arduino.h> #include "DcsBios.h" #include <Servo.h> //These int's are the 0 or 1 results called from the current state of the related LED. int StateTipL = 0; int StateOutL = 0; int StateInL = 0; int StateInR = 0; int StateOutR = 0; int StateTipR = 0; int StateAPU = 0; int StateGuard = 0; int StateXPND = 0; int StateEmHy = 0; int StateTail = 0; int LEDBrightness = 255; //LED Pins Assigned const int LEDTipL = 2; const int LEDOutL = 3; const int LEDInL = 4; const int LEDInR = 5; const int LEDOutR = 6; const int LEDTipR = 7; const int LEDAPU = 8; const int LEDGuard = 10; const int LEDXPND = 11; const int LEDEmHy = 12; const int LEDTail = 13; // Source From .Lua File The LED Brightness Values For All Signal LED's On Panels And Export To Pins. void onPltSignalLChange(unsigned int newValue) { LEDBrightness = map(newValue, 0, 65535, 0, 255); lightControl(); // Call the light control because a variable changed } DcsBios::IntegerBuffer pltSignalLBuffer(0x8734, 0xffff, 0, onPltSignalLChange); // ========================================================================= //START OF LIGHTING PANEL //Digital Inputs //External Lights 3 Position Switch. DcsBios::Switch3Pos pltExtlNavLSw("PLT_EXTL_NAV_L_SW", 22, 23); //Anti Colision Lights DcsBios::Switch3Pos pltExtlAcolLSw("PLT_EXTL_ACOL_L_SW", 24, 25); //Lighting Test Button DcsBios::Switch2Pos pltIntlTestBtn("PLT_INTL_TEST_BTN", 26); //---------------------------------------------------------------------------- //Analog Inputs //Formation Lights Knob DcsBios::Potentiometer pltExtlFromationLKnb("PLT_EXTL_FROMATION_L_KNB", A0); //Signal Lights Knob DcsBios::Potentiometer pltIntlSignalLKnb("PLT_INTL_SIGNAL_L_KNB", A1); //Flood Lights Knob DcsBios::Potentiometer pltIntlFloodLKnb("PLT_INTL_FLOOD_L_KNB", A2); //Primary Lights Knob DcsBios::Potentiometer pltIntlPrimaryLKnb("PLT_INTL_PRIMARY_L_KNB", A3); //Standby Instruments Lights Knob DcsBios::Potentiometer pltIntlStbyinstLKnb("PLT_INTL_STBYINST_L_KNB", A4); //END OF LIGHTING PANEL // ========================================================================= //START OF JETTISON PANEL //Digital Inputs //Left Tip Push DcsBios::Switch2Pos pltJettStoreLw("PLT_JETT_STORE_LW", 27); //Left Out Board Push DcsBios::Switch2Pos pltJettStoreLo("PLT_JETT_STORE_LO", 28); //Left In Board Push DcsBios::Switch2Pos pltJettStoreLi("PLT_JETT_STORE_LI", 29); //Right In Board Push DcsBios::Switch2Pos pltJettStoreRi("PLT_JETT_STORE_RI", 30); //Right Out Board Push DcsBios::Switch2Pos pltJettStoreRo("PLT_JETT_STORE_RO", 31); //Right Tip Push DcsBios::Switch2Pos pltJettStoreRw("PLT_JETT_STORE_RW", 32); //Jettison Launch Push DcsBios::Switch2Pos pltJettBtn("PLT_JETT_BTN", 33); //---------------------------------------------------------------------------- //LED Outputs //Left Tip 'ARM' void onPltJettLTipLChange(unsigned int newValue) { StateTipL = newValue; lightControl(); // Call the light control because a variable changed } DcsBios::IntegerBuffer pltJettLTipLBuffer(0x872a, 0x0100, 8, onPltJettLTipLChange); //Left Out Board 'ARM' void onPltJettLOutboardLChange(unsigned int newValue) { StateOutL = newValue; lightControl(); // Call the light control because a variable changed } DcsBios::IntegerBuffer pltJettLOutboardLBuffer(0x872a, 0x0200, 9, onPltJettLOutboardLChange); //Left In Board 'ARM' void onPltJettLInboardLChange(unsigned int newValue) { StateInL = newValue; lightControl(); // Call the light control because a variable changed } DcsBios::IntegerBuffer pltJettLInboardLBuffer(0x872a, 0x0400, 10, onPltJettLInboardLChange); //Right In Board 'ARM' void onPltJettRInboardLChange(unsigned int newValue) { StateInR = newValue; lightControl(); // Call the light control because a variable changed } DcsBios::IntegerBuffer pltJettRInboardLBuffer(0x872a, 0x0800, 11, onPltJettRInboardLChange); //Right Out Board 'ARM' // This sets the StateOutR variable based on the value of PltJettROutboardL (0-1) void onPltJettROutboardLChange(unsigned int newValue) { StateOutR = newValue; lightControl(); // Call the light control because a variable changed } DcsBios::IntegerBuffer pltJettROutboardLBuffer(0x872a, 0x2000, 13, onPltJettROutboardLChange); //Right Tip 'ARM' void onPltJettRTipLChange(unsigned int newValue) { StateTipR = newValue; lightControl(); // Call the light control because a variable changed } DcsBios::IntegerBuffer pltJettRTipLBuffer(0x872a, 0x1000, 12, onPltJettRTipLChange); //END OF JETTISON PANEL // ========================================================================= //START OF POWER PANEL //Analog Inputs //Left Power Lever DcsBios::Potentiometer pltEngLPwLvr("PLT_ENG_L_PW_LVR", A5); //Right Power Lever DcsBios::Potentiometer pltEngRPwLvr("PLT_ENG_R_PW_LVR", A6); //Friction Adjust Lever DcsBios::Potentiometer pltPwLvrFric("PLT_PW_LVR_FRIC", A7); //---------------------------------------------------------------------------- //LED Outputs //APU 'APU' void onPltApuReadyLChange(unsigned int newValue) { StateAPU = newValue; lightControl(); // Call the light control because a variable changed } DcsBios::IntegerBuffer pltApuReadyLBuffer(0x872a, 0x0001, 0, onPltApuReadyLChange); //---------------------------------------------------------------------------- //Digital Inputs //Engine 1 Start 3 Position Switch DcsBios::Switch3Pos pltEng1Start("PLT_ENG1_START", 34, 35); //Engine 2 Start 3 Position Switch DcsBios::Switch3Pos pltEng2Start("PLT_ENG2_START", 36, 37); //APU Push DcsBios::Switch2Pos pltApuBtn("PLT_APU_BTN", 38); //APU Cover Push DcsBios::Switch2Pos pltApuBtnCvr("PLT_APU_BTN_CVR", 39); //Rotor Break 3 Position Switch DcsBios::Switch3Pos pltRotorBrk("PLT_ROTOR_BRK", 40, 41); //Battery Dial 3 Position Dial DcsBios::Switch3Pos pltMasterIgnSw("PLT_MASTER_IGN_SW", 42, 43); //END OF POWER PANEL // ========================================================================= //START OF EMERGENCY PANEL //Digital Inputs //'GUARD' Push DcsBios::Switch2Pos pltEmergGuardBtn("PLT_EMERG_GUARD_BTN", 44); //'XPNDR' Push DcsBios::Switch2Pos pltEmergXpndrBtn("PLT_EMERG_XPNDR_BTN", 45); //'ZERO' Push DcsBios::Switch2Pos pltEmergZeroSw("PLT_EMERG_ZERO_SW", 46); //'EM HY' Push DcsBios::Switch2Pos pltEmergHydBtn("PLT_EMERG_HYD_BTN", 47); //---------------------------------------------------------------------------- //LED Outputs //'GUARD' Push LED void onPltEmergGuardLChange(unsigned int newValue) { StateGuard = newValue; lightControl(); // Call the light control because a variable changed } DcsBios::IntegerBuffer pltEmergGuardLBuffer(0x872a, 0x0010, 4, onPltEmergGuardLChange); //'XPNDR' Push LED void onPltEmergXpndrLChange(unsigned int newValue) { StateXPND = newValue; lightControl(); // Call the light control because a variable changed } DcsBios::IntegerBuffer pltEmergXpndrLBuffer(0x872a, 0x0020, 5, onPltEmergXpndrLChange); //'EM HY' Push LED void onPltEmergHydLChange(unsigned int newValue) { StateEmHy = newValue; lightControl(); // Call the light control because a variable changed } DcsBios::IntegerBuffer pltEmergHydLBuffer(0x872a, 0x0040, 6, onPltEmergHydLChange); //END OF EMERGENCY PANEL // ========================================================================= //START OF NVS PANEL //Digital Inputs //'Tail Wheel' Push DcsBios::Switch2Pos pltTWheelUnlockBtn("PLT_T_WHEEL_UNLOCK_BTN", 48); //'NVS' 3 Position Switch DcsBios::Switch3Pos pltNvsMode("PLT_NVS_MODE", 49, 50); //---------------------------------------------------------------------------- //LED Outputs //'Tail Wheel' LED void onPltTWheelUnlockLChange(unsigned int newValue) { StateTail = newValue; lightControl(); // Call the light control because a variable changed } DcsBios::IntegerBuffer pltTWheelUnlockLBuffer(0x872a, 0x0080, 7, onPltTWheelUnlockLChange); //END OF NVS PANEL // ========================================================================= void setup() { DcsBios::setup(); pinMode(LEDTipL, OUTPUT); pinMode(LEDOutL, OUTPUT); pinMode(LEDInL, OUTPUT); pinMode(LEDInR, OUTPUT); pinMode(LEDOutR, OUTPUT); pinMode(LEDTipR, OUTPUT); pinMode(LEDAPU, OUTPUT); pinMode(LEDGuard, OUTPUT); pinMode(LEDXPND, OUTPUT); pinMode(LEDEmHy, OUTPUT); pinMode(LEDTail, OUTPUT); } void loop() { DcsBios::loop(); } // This controls the light based on the variable values void lightControl() { //Left Tip 'Arm' if (StateTipL == 1) { analogWrite (LEDTipL, LEDBrightness); } else { analogWrite (LEDTipL, 0); } //Left Out 'Arm' if (StateOutL == 1) { analogWrite (LEDOutL, LEDBrightness); } else { analogWrite (LEDOutL, 0); } //Left In 'Arm' if (StateInL == 1) { analogWrite (LEDInL, LEDBrightness); } else { analogWrite (LEDInL, 0); } //Right In 'Arm' if (StateInR == 1) { analogWrite (LEDInR, LEDBrightness); } else { analogWrite (LEDInR, 0); } //Right Out 'Arm' if (StateOutR == 1) { analogWrite (LEDOutR, LEDBrightness); } else { analogWrite (LEDOutR, 0); } //Right Tip 'Arm' if (StateTipR == 1) { analogWrite (LEDTipR, LEDBrightness); } else { analogWrite (LEDTipR, 0); } //'APU' if (StateAPU == 1) { analogWrite (LEDAPU, LEDBrightness); } else { analogWrite (LEDAPU, 0); } //'Guard' if (StateGuard == 1) { analogWrite (LEDGuard, LEDBrightness); } else { analogWrite (LEDGuard, 0); } //'XPND' if (StateXPND == 1) { analogWrite (LEDXPND, LEDBrightness); } else { analogWrite (LEDXPND, 0); } //'Emergency Hydrolics' if (StateEmHy == 1) { analogWrite (LEDEmHy, LEDBrightness); } else { analogWrite (LEDEmHy, 0); } //'Tail' Wheel if (StateTail == 1) { analogWrite (LEDTail, LEDBrightness); } else { analogWrite (LEDTail, 0); } } Thanks again No1sonuk.
  4. Ok so with that code it will control the brightness of the LED's, but I need to analogWrite to all the LED's which need to be dimmed, and they will all light up to that brightness despite if they should be in an off state. I'm trying to implement something like this: int StateOutR = 0; int LEDBrightness = 255; const int LEDOutR = 6; void onPltSignalLChange(unsigned int newValue) { LEDBrightness = map(newValue, 0, 65535, 0, 255); } DcsBios::IntegerBuffer pltSignalLBuffer(0x8734, 0xffff, 0, onPltSignalLChange); //Right Out Board 'ARM' DcsBios::LED pltJettROutboardL(0x872a, 0x2000, StateOutR); void setup() { DcsBios::setup(); pinMode(6, OUTPUT); } void loop() { if (StateOutR == 1) { analogWrite (LEDOutR, LEDBrightness); } else { analogWrite (LEDOutR, 0); } DcsBios::loop(); } Obviously the code above is extremely cut down to the relevant lines of code. So what I'm now trying to do is source the brightness value through 'PltSignalBuffer' and remapping to a variable called 'LEDBrightness'. Then sourcing if the on/off state of the ' Right Out Board' LED should be on or off and assigning a variable called 'StateOutR' with a 0 or 1 depending. (One thing I'm not sure of is can I replace the (PIN) part of the DcsBios::LED pltJettROutboardL(0x872a, 0x2000, StateOutR); with a variable integer (StateOutR) or does it have to export that to a PIN?) Then in the Void Setup I'm assigning Pin 6 to an Analog output. Then in Void Loop I'm asking for it to check if 'StateOutR' is a 0 or 1 (If the led should be on or off in DCS). If 'StateOutR' is 1, then set analog pin 6 to the value LEDBrightness is set to. If 'StateOutR' is 0, then set analog pin 6 to 0. I cant see any problem with this but currently the LED wont light up at all. My theory is I cant export the 0 or 1 state to a variable, maybe it must be a PIN.
  5. G'day No1sonuk. I think that is what I was trying when I first implemented a code which did successfully dim the LED's. I used 'AH-64D/PLT_SIGNAL_L' integer which seems to be the only value which changes with the LED's in DCS. My problem was that when I would active the call back to the onchange command of the signal potentiometer it would turn all the LED's on regardless of if they should be on or off. For example, is there a way of injecting a PMW output value into the 'DcsBios::LED pltApuReadyL(0x872a, 0x0001, PIN); line of code? Like with a normal C++ code its easy to just dim an LED with a simple code like ' LEDBrightness = 250; analogWrite(5, LEDBrightness); Now I cant use the analog read value from the potentiometer as with the AH64 the brightness of the LED's are not directly dictated by just the 'Signal' knob, as in I can have the 'Signal' knob at 20% and it does display all the LED's at the correct 20%, but if you turn the 'Flood' knob higher than 50% then i will turn all LED's to 100% brightness, despite the position of the "Signal' knob. (which is the correct function). So the only integer value which I can find which follows the rules of the 'Flood' and 'Signal' functions is the "AH-64D/PLT_SIGNAL_L" (Pilot Signal Light (multi color))'. Which I can read the integer value received through DCS Bios, but I don't understand how to control the brightness of the LED's with that value. I can control the brightness by adding the for example :analogWrite(5, LEDBrightness); (which I would add after the "void onPltSignalLChange(unsigned int newValue) {", then with a remap from 0-255) which will dim the LED's, but it will not then follow the rules of if that LED should be in a on or off state. On a side note, I have no idea why the code I posted in the first post is so spaced out. Is there a better way of posting the code as that is super hard to read? Cheers
  6. G'day Lads. Iv been on and off building a panel for the AH64, I have finally reached the point in the project of writing the code for DCS Bios integration. I have compiled a code which works perfectly which includes - Button inputs (Digital in), potentiometer inputs (Analog in), LED's (PWM Out). I want to add the function of having the LED brightness on the physical panel match the LED brightness value sourced from DCS Bios for the same panel displayed in DCS. I have found the only integer which updates on Bort when I change the brightness of the LED's in DCS is the 'Pilot Signal Light (multi color)'. The integer values for each individual LED only gives a 1 or 0 output, there is no 0 - 65535 value sourced through DCS Bios. I have tried for multiple hours to incorporate the "void onPltSignalLChange" section of code, with a remap to 0 - 255, then update a global integer with that value. I don't understand how to set the brightness of each LED PWM with that new value. I managed to code it so the Physical LED's would show the correct brightness value sourced from 'Pilot Signal Light (multi color)', but my issue was that all the LED's would light up to that brightness value, despite some of the LED's should have been off completely. All LED's would light up to that value anytime the onchange command for 'Pilot Signal Light (multi color)' as activated. Then when I would update the box with a command to turn an LED on or off, all the LED's would display the correct on/off state, but would all be at max brightness. I have reverted all the code back to the point just before I started adding the LED Brightness code. Any help would be greatly appreciated as I am not familiar enough with the DCS Bios library. Cheers Here is my current code. // AH64 Left Hand Console // Arduino Mega 2560 //WIP - Need to write new code for- //Servo Output/Friction Lever. //Add LED Brightness sourced from Pilot Signal Light. //WIP #define DCSBIOS_IRQ_SERIAL #include <Arduino.h> #include "DcsBios.h" #include <Servo.h> unsigned int ledIntensity = 0; // Initial intensity (0 to 255, where 0 is off and 255 is full brightness). // Source From .Lua File The LED Brightness Values For All Signal LED's On Panels And Export To Pins. // ========================================================================= //START OF LIGHTING PANEL //Digital Inputs //External Lights 3 Position Switch. DcsBios::Switch3Pos pltExtlNavLSw("PLT_EXTL_NAV_L_SW", 22, 23); //Anti Colision Lights DcsBios::Switch3Pos pltExtlAcolLSw("PLT_EXTL_ACOL_L_SW", 24, 25); //Lighting Test Button DcsBios::Switch2Pos pltIntlTestBtn("PLT_INTL_TEST_BTN", 26); //---------------------------------------------------------------------------- //Analog Inputs //Formation Lights Knob DcsBios::Potentiometer pltExtlFromationLKnb("PLT_EXTL_FROMATION_L_KNB", A0); //Signal Lights Knob DcsBios::Potentiometer pltIntlSignalLKnb("PLT_INTL_SIGNAL_L_KNB", A1); //Flood Lights Knob DcsBios::Potentiometer pltIntlFloodLKnb("PLT_INTL_FLOOD_L_KNB", A2); //Primary Lights Knob DcsBios::Potentiometer pltIntlPrimaryLKnb("PLT_INTL_PRIMARY_L_KNB", A3); //Standby Instruments Lights Knob DcsBios::Potentiometer pltIntlStbyinstLKnb("PLT_INTL_STBYINST_L_KNB", A4); //END OF LIGHTING PANEL // ========================================================================= //START OF JETTISON PANEL //Digital Inputs //Left Tip Push DcsBios::Switch2Pos pltJettStoreLw("PLT_JETT_STORE_LW", 27); //Left Out Board Push DcsBios::Switch2Pos pltJettStoreLo("PLT_JETT_STORE_LO", 28); //Left In Board Push DcsBios::Switch2Pos pltJettStoreLi("PLT_JETT_STORE_LI", 29); //Right In Board Push DcsBios::Switch2Pos pltJettStoreRi("PLT_JETT_STORE_RI", 30); //Right Out Board Push DcsBios::Switch2Pos pltJettStoreRo("PLT_JETT_STORE_RO", 31); //Right Tip Push DcsBios::Switch2Pos pltJettStoreRw("PLT_JETT_STORE_RW", 32); //Jettison Launch Push DcsBios::Switch2Pos pltJettBtn("PLT_JETT_BTN", 33); //---------------------------------------------------------------------------- //LED Outputs //Left Tip 'ARM' DcsBios::LED pltJettLTipL(0x872a, 0x0100, 2); //Left Out Board 'ARM' DcsBios::LED pltJettLOutboardL(0x872a, 0x0200, 3); //Left In Board 'ARM' DcsBios::LED pltJettLInboardL(0x872a, 0x0400, 4); //Right In Board 'ARM' DcsBios::LED pltJettRInboardL(0x872a, 0x0800, 5); //Right Out Board 'ARM' DcsBios::LED pltJettROutboardL(0x872a, 0x2000, 6); //Right Tip 'ARM' DcsBios::LED pltJettRTipL(0x872a, 0x1000, 7); //END OF JETTISON PANEL // ========================================================================= //START OF POWER PANEL //Analog Inputs //Left Power Lever DcsBios::Potentiometer pltEngLPwLvr("PLT_ENG_L_PW_LVR", A5); //Right Power Lever DcsBios::Potentiometer pltEngRPwLvr("PLT_ENG_R_PW_LVR", A6); //Friction Adjust Lever DcsBios::Potentiometer pltPwLvrFric("PLT_PW_LVR_FRIC", A7); //---------------------------------------------------------------------------- //LED Outputs //APU 'APU' DcsBios::LED pltApuL(0x872c, 0x0002, 8); //---------------------------------------------------------------------------- //Digital Inputs //Engine 1 Start 3 Position Switch DcsBios::Switch3Pos pltEng1Start("PLT_ENG1_START", 34, 35); //Engine 2 Start 3 Position Switch DcsBios::Switch3Pos pltEng2Start("PLT_ENG2_START", 36, 37); //APU Push DcsBios::Switch2Pos pltApuBtn("PLT_APU_BTN", 38); //APU Cover Push DcsBios::Switch2Pos pltApuBtnCvr("PLT_APU_BTN_CVR", 39); //Rotor Break 3 Position Switch DcsBios::Switch3Pos pltRotorBrk("PLT_ROTOR_BRK", 40, 41); //Battery Dial 3 Position Dial DcsBios::Switch3Pos pltMasterIgnSw("PLT_MASTER_IGN_SW", 42, 43); //---------------------------------------------------------------------------- //END OF POWER PANEL // ========================================================================= //START OF EMERGENCY PANEL //Digital Inputs //'GUARD' Push DcsBios::Switch2Pos pltEmergGuardBtn("PLT_EMERG_GUARD_BTN", 44); //'XPNDR' Push DcsBios::Switch2Pos pltEmergXpndrBtn("PLT_EMERG_XPNDR_BTN", 45); //'ZERO' Push DcsBios::Switch2Pos pltEmergZeroSw("PLT_EMERG_ZERO_SW", 46); //'EM HY' Push DcsBios::Switch2Pos pltEmergHydBtn("PLT_EMERG_HYD_BTN", 47); //---------------------------------------------------------------------------- //LED Outputs //'GUARD' Push LED DcsBios::LED pltEmergGuardL(0x872a, 0x0010, 10); //'XPNDR' Push LED DcsBios::LED pltEmergXpndrL(0x872a, 0x0020, 11); //'EM HY' Push LED DcsBios::LED pltEmergHydL(0x872a, 0x0040, 12); //END OF EMERGENCY PANEL // ========================================================================= //START OF NVS PANEL //Digital Inputs //'Tail Wheel' Push DcsBios::Switch2Pos pltTWheelUnlockBtn("PLT_T_WHEEL_UNLOCK_BTN", 48); //'NVS' 3 Position Switch DcsBios::Switch3Pos pltNvsMode("PLT_NVS_MODE", 49, 50); //---------------------------------------------------------------------------- //LED Outputs //'Tail Wheel' LED DcsBios::LED pltTWheelUnlockL(0x872a, 0x0080, 13); //END OF NVS PANEL // ========================================================================= void setup() { DcsBios::setup(); } void loop() { DcsBios::loop(); }
×
×
  • Create New...