Candiru89 Posted January 27, 2022 Posted January 27, 2022 Hello! Is there a way to invert a LEDs function? So when it turns on in the cockpit it turns off on my button box and vice versa? Like he "true" command for switches.
No1sonuk Posted January 27, 2022 Posted January 27, 2022 I know you can do it in hardware. The arduinos can source or sink enough current for LEDs. See attached. For DCS-BIOS, you'd normally wire an LED as in "active high" - LED comes on when line goes high (on). BUT, if you wire it as in "active low", the LED will come on when the line goes low (off). No code change required - just assume the LED will do the opposite of the pin.
Candiru89 Posted January 27, 2022 Author Posted January 27, 2022 31 minutes ago, No1sonuk said: I know you can do it in hardware. The arduinos can source or sink enough current for LEDs. See attached. For DCS-BIOS, you'd normally wire an LED as in "active high" - LED comes on when line goes high (on). BUT, if you wire it as in "active low", the LED will come on when the line goes low (off). No code change required - just assume the LED will do the opposite of the pin. So if I understand correctly, I have to connect + side to one of the I/O pins and - side to 5V? As a side affect it will be always on when the board is powered, isn't it?
No1sonuk Posted January 27, 2022 Posted January 27, 2022 2 hours ago, Candiru89 said: So if I understand correctly, I have to connect + side to one of the I/O pins and - side to 5V? As a side affect it will be always on when the board is powered, isn't it? No. The + side to 5V and the - to the I/O pin. In other words, move the arduino from above the LED to below it. The LED will be on if the pin is off. The other method I can think of uses the onchange code with the LED wired the normal way. Which particular LED are you thinking of?
Candiru89 Posted January 27, 2022 Author Posted January 27, 2022 13 minutes ago, No1sonuk said: No. The + side to 5V and the - to the I/O pin. In other words, move the arduino from above the LED to below it. The LED will be on if the pin is off. The other method I can think of uses the onchange code with the LED wired the normal way. Which particular LED are you thinking of? Oh, okay. In the ka-50 I want an led to show the gun ammo type. It works, the led is on when the switch is in up position (HE), and its off in down position (API), but I want the other way around.
No1sonuk Posted January 27, 2022 Posted January 27, 2022 (edited) OK... Let's assume I have no idea about what any of the KA-50 switches or LEDs do. I'll be more specific... What is the name of the switch and/or LED in the DCS-BIOS control reference? Edit: Or even post your code snippet for what you have working. Edited January 27, 2022 by No1sonuk
Candiru89 Posted January 27, 2022 Author Posted January 27, 2022 1 hour ago, No1sonuk said: OK... Let's assume I have no idea about what any of the KA-50 switches or LEDs do. I'll be more specific... What is the name of the switch and/or LED in the DCS-BIOS control reference? Edit: Or even post your code snippet for what you have working. DcsBios::LED weaponsCannonRound(0x1886, 0x0008, 8);
No1sonuk Posted January 28, 2022 Posted January 28, 2022 OK Try this instead of that LED line: void onWeaponsCannonRoundChange(unsigned int newValue) { if (newValue==1){ // If the value is 1, set the LED off digitalWrite (CannonRoundLEDpin, LOW); // I'd suggest using pin labels like this to keep track easier } // Just declare them as constants at the beginning of the code else{ // If the value is not 1, set the LED on digitalWrite (CannonRoundLEDpin, HIGH); } } DcsBios::IntegerBuffer weaponsCannonRoundBuffer(0x1886, 0x0008, 3, onWeaponsCannonRoundChange); Don't forget to leave the LED connected as normal.
Candiru89 Posted January 29, 2022 Author Posted January 29, 2022 On 1/28/2022 at 2:03 AM, No1sonuk said: OK Try this instead of that LED line: void onWeaponsCannonRoundChange(unsigned int newValue) { if (newValue==1){ // If the value is 1, set the LED off digitalWrite (CannonRoundLEDpin, LOW); // I'd suggest using pin labels like this to keep track easier } // Just declare them as constants at the beginning of the code else{ // If the value is not 1, set the LED on digitalWrite (CannonRoundLEDpin, HIGH); } } DcsBios::IntegerBuffer weaponsCannonRoundBuffer(0x1886, 0x0008, 3, onWeaponsCannonRoundChange); Don't forget to leave the LED connected as normal. Thank you very much for your effort, this code works, I could set up an other led output that I want to use similar, based on this. There is only one problem now: These 2 leds light barely. If I change them back how I used earlier (what I copied in my previous comment) there light very bright but with your code its barely visible. What is the reason for that?
No1sonuk Posted January 29, 2022 Posted January 29, 2022 10 hours ago, Candiru89 said: These 2 leds light barely. If I change them back how I used earlier (what I copied in my previous comment) there light very bright but with your code its barely visible. What is the reason for that? For that code to work, your LED needs to be wired as in the "active high" drawing in my earlier post. Can you draw how yours is connected?
Candiru89 Posted January 30, 2022 Author Posted January 30, 2022 (edited) On 1/29/2022 at 1:30 PM, No1sonuk said: For that code to work, your LED needs to be wired as in the "active high" drawing in my earlier post. Can you draw how yours is connected? Its connected as active high. Its D07, with the purple wire. Edited January 30, 2022 by Candiru89
No1sonuk Posted January 30, 2022 Posted January 30, 2022 It might be pulsing because there's no previous state detection in that code I posted. OR Did you remove the original LED code line? If you didn't, one is trying to turn it on and the other is trying to turn it off. BTW, I looked in the DCS-BIOS Flightpanels Fork source code, and there doesn't appear to be a "true" or "false" type option in it.
Candiru89 Posted January 30, 2022 Author Posted January 30, 2022 2 hours ago, No1sonuk said: It might be pulsing because there's no previous state detection in that code I posted. OR Did you remove the original LED code line? If you didn't, one is trying to turn it on and the other is trying to turn it off. BTW, I looked in the DCS-BIOS Flightpanels Fork source code, and there doesn't appear to be a "true" or "false" type option in it. Yes, I removed the original LED code line.
No1sonuk Posted January 30, 2022 Posted January 30, 2022 Try this: // These need to be at the top of the code int CannonRoundState = 0; // Global variable for checking the state of the light const int CannonRoundLEDpin = 13; // The pin that the LED is attached to // This needs to be in the void setup section: pinMode(CannonRoundLEDpin, OUTPUT); // This goes with the DCS-BIOS code: void onWeaponsCannonRoundChange(unsigned int newValue) { if (newValue != CannonRoundState) { if (newValue==1){ // If the value is 1, set the LED off digitalWrite (CannonRoundLEDpin, LOW); // I'd suggest using pin labels like this to keep track easier } // Just declare them as constants at the beginning of the code else{ // If the value is not 1, set the LED on digitalWrite (CannonRoundLEDpin, HIGH); } } CannonRoundState = newValue; } DcsBios::IntegerBuffer weaponsCannonRoundBuffer(0x1886, 0x0008, 3, onWeaponsCannonRoundChange); I've added previous state checking and the other lines needed to make it work.
Candiru89 Posted February 5, 2022 Author Posted February 5, 2022 On 1/30/2022 at 11:51 PM, No1sonuk said: I've added previous state checking and the other lines needed to make it work. Hello! Sorry for not answering so long, but my PC (the system ssd) broke last weekend without a warning and spent my last week with repair, reinstall and reorganize everything. But now I have a few minutes to fire up DCS and Arduino and the latest code you gave me works perfectly, thank you very much for your time and effort, my gratitude will chase you to the grave!
byteman59 Posted April 19, 2022 Posted April 19, 2022 No1sonuk, I'm using an LED with a Vf of 3.2V. I am getting the following results when calculating R and W. 5V-3.2V/.02mA=90 ohms 5V-3.2V ^2/90 ohms=.169W Should i round up and use a 100ohm 1/4W resistor? btw, newbie to electronics, my area is computer networking and engineering. Thanks!
No1sonuk Posted April 19, 2022 Posted April 19, 2022 3 hours ago, byteman59 said: No1sonuk, I'm using an LED with a Vf of 3.2V. I am getting the following results when calculating R and W. 5V-3.2V/.02mA=90 ohms 5V-3.2V ^2/90 ohms=.169W Should i round up and use a 100ohm 1/4W resistor? btw, newbie to electronics, my area is computer networking and engineering. Thanks! Do you need the full brightness? I tend to use 220 Ohm. That gives a reasonable current for a wide variety of LED voltages - IIRC, standard Reds are 2.2V.
byteman59 Posted April 19, 2022 Posted April 19, 2022 19 minutes ago, No1sonuk said: Do you need the full brightness? I tend to use 220 Ohm. That gives a reasonable current for a wide variety of LED voltages - IIRC, standard Reds are 2.2V. Planning on using a dimmer in the circuit. I'm using green LED with a rated Vf of 3.2
byteman59 Posted August 10, 2022 Posted August 10, 2022 What is the difference between using the following to light up an LED? LED DcsBios::LED efcpMrfcs(0x110c, 0x0800, PIN); IntegerBuffer void onEfcpTrimOverrideChange(unsigned int newValue) { /* your code here */ } DcsBios::IntegerBuffer efcpTrimOverrideBuffer(0x110c, 0x0004, 2, onEfcpTrimOverrideChange);
No1sonuk Posted August 10, 2022 Posted August 10, 2022 DcsBios::LED efcpMrfcs(0x110c, 0x0800, PIN); Lights an LED as an indicator for a switch input. DcsBios::IntegerBuffer efcpTrimOverrideBuffer(0x110c, 0x0004, 2, onEfcpTrimOverrideChange); Runs the code in the onEfcpTrimOverrideChange function when the switch changes. Note they're for different switches
No1sonuk Posted August 11, 2022 Posted August 11, 2022 OK. But those are not what you asked about. You asked about 2 different controls. The "0x0800" is the "bit mask" to isolate the bit you want from the "0x110C" address. The rest of my response stands. The LED code switches an LED on and off dependent on the state of the bit. The IntergerBuffer code feeds the value (1 or 0 in this case) into a function you write. "DcsBios::IntegerBuffer efcpMrfcsBuffer(0x110c, 0x0800, 11, onEfcpMrfcsChange)" means take bit 0x0800 from address 0x110c, shift it 11 places to the right, then feed it to the function named "onEfcpMrfcsChange". The shift is so that the value is 1 or 0 rather than 2048 or 0. DcsBios::LED efcpMrfcs(0x110c, 0x0800, LED_PIN); Will do the same as this: void onEfcpMrfcsChange(unsigned int newValue) { if (newValue == 1) { digitalWrite(LED_PIN, HIGH); } else { digitalWrite(LED_PIN, LOW); } } DcsBios::IntegerBuffer efcpMrfcsBuffer(0x110c, 0x0800, 11, onEfcpMrfcsChange); But the second one could also be used to carry out other actions based on the newValue number.
byteman59 Posted August 12, 2022 Posted August 12, 2022 My applogy for the misunderstanding and mistake. So if my LED is doing the opposite of what is expected, while using the LED code, i can use the IntegerBuffer code and have it do the opposite? For example, my LED's for Aileron and Elevator are on by default, and when switches are moved, then they turn off.
No1sonuk Posted August 12, 2022 Posted August 12, 2022 If you try the "active low" wiring from my first response to this thread, it might do what you want.
Recommended Posts