Jump to content

Rotary Encoder W/Switch, LED and Arduino Help Please


Recommended Posts

Posted

I'm building the Intercom Panel for the A10 and this is how I'm wanting to build it, but need some help. I'm using rotary encoders with switches for the volume knobs, and an Arduino Mega to be used with DCS Bios. I want to wire the knobs so that they are "turned on" only when I push the encoder switch, and turned off when I push it again. Along with this, I'd like to wire an LED backlight for the panel to light up when I push the switch, showing me that volume knob is "on" or "active", and then turned off when I push the switch again. So how do I wire the rotary encoder with switch (GND, +, SW, DT, CLK), the LED (+,-) and Arduino Mega. Thank you for any help! 

Windows 10

ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO

intel i7-8700k (Not overclocked)

16 GB Ram

EVGA GeForce GTX 108ti SC Black Edition

SSD

Trackir

Posted (edited)

Hi Ken,

You need 4 pins for each of the functions: 2 digital pins for the rotary, 1 digital pin for the switch and 1 pin for the corresponding LED. All can have a common pin to the GND signal.

The (+) mostly is not necessary as the positive voltage is provided from the digital pins (internal pullup). Some rotaries do have (+) pin, that is to be connected to the Arduino 5V rail.

For the DcsBios part you may work with the "action button" function and  "state machines".

 

Regards, Vinc 

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted

Hey Vinc! Thanks for the response. Unforunately I'm not familiar with how to use the "action button" function and "state machines" in DCS Bios. The only thing I know how to do is copy and paste the sketch language from DCS Bios to the Arduino. I don't know what the coding means or how to write my own. Do you know of any tutorials or videos for beginners that would hep me understand them so I can figure this out?

 

Windows 10

ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO

intel i7-8700k (Not overclocked)

16 GB Ram

EVGA GeForce GTX 108ti SC Black Edition

SSD

Trackir

Posted (edited)

Hi Ken,

For the actionbutton function have a look into the below linked DcsBios documentation. Scroll down and find some examples. To make it short, an actionbutton is a pushbutton that can toggle between ON and OFF. That's what you need to enable or disable the respective rotary by its pushbutton.

https://dcs-bios.readthedocs.io/en/latest/code-snippets.html

A state machine is a piece of code that enables you to switch between several known states to do something. For your application a dedicated rotary should be responsive or not. That already are two states. So the rotary's pushbutton may be programmed to send either the ON or the OFF state of the respective rotary to DcsBios. 

You than read in either 1 or 0 into a variable and can use an if-else loop or case-switch to activate or de-activate the rotary.

 

 

Edit: The solution is simpler after I had a detailed look into Bort, because we have the opportunity to use the Mute/Unmute function for the Intercom Panel switches. So the "state machine" is already provided to us by DcsBios.

Example for the INT switch and rotary encoder:

 

// ----- INT Un-Mute input and output, INT volume adjustment -----
DcsBios::ActionButton intIntUnmuteToggle("INT_INT_UNMUTE", "TOGGLE", 10); // INT switch on pin 10 for the INT Un-Mute switch
DcsBios::RotaryEncoder intIntVol("INT_INT_VOL", "-3200", "+3200", 11, 12); //  INT volume rotary is connected to pins 11 and 12
DcsBios::LED intIntUnmute(0x1194, 0x8000, 13); //  a LED shows if the volume adjustment is active

That's all for one of the Intercom Panel switches.

 

Regards, Vinc

 

 

Intercom_example_01.ino

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted

Thanks so much Vinc!!! I appreciate you taking the time to look that up and send me the sketch for it. I'm still going to check out the link you sent as well to try and educate myself on this stuff. I'm going to try this out in the next few days and hopefully get it working. Thanks again!! :notworthy:

Windows 10

ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO

intel i7-8700k (Not overclocked)

16 GB Ram

EVGA GeForce GTX 108ti SC Black Edition

SSD

Trackir

Posted (edited)

It worked!! Thanks again Vinc!! 

 

Edited by Kenpilot

Windows 10

ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO

intel i7-8700k (Not overclocked)

16 GB Ram

EVGA GeForce GTX 108ti SC Black Edition

SSD

Trackir

  • 8 months later...
Posted
On 3/27/2024 at 2:05 PM, Vinc_Vega said:

Hi Ken,

For the actionbutton function have a look into the below linked DcsBios documentation. Scroll down and find some examples. To make it short, an actionbutton is a pushbutton that can toggle between ON and OFF. That's what you need to enable or disable the respective rotary by its pushbutton.

https://dcs-bios.readthedocs.io/en/latest/code-snippets.html

A state machine is a piece of code that enables you to switch between several known states to do something. For your application a dedicated rotary should be responsive or not. That already are two states. So the rotary's pushbutton may be programmed to send either the ON or the OFF state of the respective rotary to DcsBios. 

You than read in either 1 or 0 into a variable and can use an if-else loop or case-switch to activate or de-activate the rotary.

 

 

Edit: The solution is simpler after I had a detailed look into Bort, because we have the opportunity to use the Mute/Unmute function for the Intercom Panel switches. So the "state machine" is already provided to us by DcsBios.

Example for the INT switch and rotary encoder:

 

// ----- INT Un-Mute input and output, INT volume adjustment -----
DcsBios::ActionButton intIntUnmuteToggle("INT_INT_UNMUTE", "TOGGLE", 10); // INT switch on pin 10 for the INT Un-Mute switch
DcsBios::RotaryEncoder intIntVol("INT_INT_VOL", "-3200", "+3200", 11, 12); //  INT volume rotary is connected to pins 11 and 12
DcsBios::LED intIntUnmute(0x1194, 0x8000, 13); //  a LED shows if the volume adjustment is active

That's all for one of the Intercom Panel switches.

 

Regards, Vinc

 

 

Intercom_example_01.ino 1.83 kB · 21 downloads

Hey Vinc, hope you're doing well. Back to working on my sim after takin some time off. I'm trying to finish my A10 INT panel and when I used this sketch for just one of the switches, lets say the INT switch, it worked exactly how I wanted. I push the encoder switch, and it umutes the volume and the LED lights up. Only problem is, it also lights up all of the remaining LEDs for each switch as well. and when I activate the switch on any of the other volumes, it will unmute the volume, but the LED won't light up when its unmuted. Can you please look at my sketch and see if something is wrong in the coding or is it maybe the wiring? I do have all the grounds connected together, but each LED + is connected to its own pin on the arduino. I only have 3 volumes/switches in the sketch for now while I'm testing it.  Thanks for any help you can give!

 

/*
  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).
 */
#define DCSBIOS_IRQ_SERIAL
 
#include "DcsBios.h"
 
#include "LedControl.h"
 
DcsBios::Switch2Pos intCall("INT_CALL", A14);
 
const byte intModePins[4] = {A4, A3, A2, A1};
DcsBios::SwitchMultiPos intMode("INT_MODE", intModePins, 4);
 
DcsBios::Potentiometer intVol("INT_VOL", A0);
 
// ----- INT Un-Mute input and output, INT volume adjustment -----
DcsBios::ActionButton intIntUnmuteToggle("INT_INT_UNMUTE", "TOGGLE", A5); // INT switch on pin 10 for the INT Un-Mute switch
typedef DcsBios::RotaryEncoderT<POLL_EVERY_TIME, DcsBios::FOUR_STEPS_PER_DETENT> FourStepRotaryEncoder;
FourStepRotaryEncoder intIntVol ("INT_INT_VOL", "-1500", "+1500", 2, 3);
DcsBios::LED intIntUnmute(0x1194, 0x8000, 25); //  a LED shows if the volume adjustment is active
 
DcsBios::ActionButton intFmUnmuteToggle("INT_FM_UNMUTE", "TOGGLE", A6); // INT switch on pin 10 for the INT Un-Mute switch
typedef DcsBios::RotaryEncoderT<POLL_EVERY_TIME, DcsBios::FOUR_STEPS_PER_DETENT> FourStepRotaryEncoder;
FourStepRotaryEncoder intFmVol ("INT_FM_VOL", "-1500", "+1500", 6, 7);
DcsBios::LED intFmUnmute(0x1194, 0x8000, 29);
 
DcsBios::ActionButton intVhfUnmuteToggle("INT_VHF_UNMUTE", "TOGGLE", A7); // INT switch on pin 10 for the INT Un-Mute switch
typedef DcsBios::RotaryEncoderT<POLL_EVERY_TIME, DcsBios::FOUR_STEPS_PER_DETENT> FourStepRotaryEncoder;
FourStepRotaryEncoder intVhfVol ("INT_VHF_VOL", "-1500", "+1500", 4, 5);
DcsBios::LED intVhfUnmute(0x1194, 0x8000, 33);
 
void setup() {
  DcsBios::setup();
}
 
void loop() {
  DcsBios::loop();
}

Windows 10

ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO

intel i7-8700k (Not overclocked)

16 GB Ram

EVGA GeForce GTX 108ti SC Black Edition

SSD

Trackir

Posted (edited)

Hi Ken,

I'll do a check tonight and update this message.

For now, you may check the wiring as the LEDs mostly are controlled by their GND pins.

Regards, Vinc 

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted

I see two things.

1) The four step rotary encoder typedef is only needed once before you use it any number of times.

typedef DcsBios::RotaryEncoderT<POLL_EVERY_TIME, DcsBios::FOUR_STEPS_PER_DETENT> FourStepRotaryEncoder

2) Your LED lines are all using the same address and mask - 0x1194, 0x8000.

That's why the all come on together, and why none of the other buttons affect them. That needs to be different for each LED to behave separately. I don't have access to the control reference to tell you what they should be, but the 0x8000 part is most likely different for each LED you want.

Posted

Thanks guys. I was curious if the LED addresses needed to be different. I'm not sure if BORT will have individual address for the LEDs as this programming isn't how it actually acts in the game. I believe the lighting for the volume names are simply panel backlighting in the game, they don't individually light up when activated in the game, that's just how I wanted to program it so I know which ones are unmuted since I don't have pop up volume controls like the actual aircraft. Any idea how else to determine or create an address for each LED? 

Or if they are controlled by their GND pin, I'll need to rewire them so they are each grounded individually instead of all being a common ground as I have them wired now.

Windows 10

ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO

intel i7-8700k (Not overclocked)

16 GB Ram

EVGA GeForce GTX 108ti SC Black Edition

SSD

Trackir

Posted (edited)

Hi Ken,

I did a quick breadbord test and confirm your LED wiring and the code snippets.

If you want to have the LED on when a rotary is active (un-mute), the LEDs must be controlled by their positive ends. All GND pins therefore can be connected.

 

Like @No1sonuk already mentioned, the LED addresses must be different. Like:

DcsBios::LED intIntUnmute(0x1194, 0x8000, 13); //  a LED shows if the INT volume adjustment is active

DcsBios::LED intFmUnmute(0x119c, 0x8000, PIN); // for the FM volume

DcsBios::LED intVhfUnmute(0x11a6, 0x0001, PIN); // for the VHF volume

and so on

 

If you are not sure for a dedicated address, you may compare it to the regular output statements.

// regular statement for the VHF volume unmute (0x11a6, 0x0001)
void onIntVhfUnmuteChange(unsigned int newValue) {
    /* your code here */
}
DcsBios::IntegerBuffer intVhfUnmuteBuffer(0x11a6, 0x0001, 0, onIntVhfUnmuteChange);

// LED address for the VHF volume unmute (0x11a6, 0x0001) same as above
DcsBios::LED intVhfUnmute(0x11a6, 0x0001, PIN);

 

For the rotaries you have to see, what works best with your setup. The rest of the code should work as expected.

You also may remove the #include "LedControl.h" statement from this sketch.

 

Have a nice weekend.

Regards, Vinc

 

Edit: find below a list of the Intercom Panel Unmute LED statements from Bort

DcsBios::LED intAimUnmute(0x11a6, 0x0004, PIN);
DcsBios::LED intFmUnmute(0x119c, 0x8000, PIN);
DcsBios::LED intIffUnmute(0x11a6, 0x0008, PIN);
DcsBios::LED intIlsUnmute(0x11a6, 0x0010, PIN);
DcsBios::LED intIntUnmute(0x1194, 0x8000, PIN);
DcsBios::LED intTcnUnmute(0x11a6, 0x0020, PIN);
DcsBios::LED intUhfUnmute(0x11a6, 0x0002, PIN);
DcsBios::LED intVhfUnmute(0x11a6, 0x0001, PIN);

 

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted
4 hours ago, Vinc_Vega said:

Hi Ken,

I did a quick breadbord test and confirm your LED wiring and the code snippets.

If you want to have the LED on when a rotary is active (un-mute), the LEDs must be controlled by their positive ends. All GND pins therefore can be connected.

 

Like @No1sonuk already mentioned, the LED addresses must be different. Like:

DcsBios::LED intIntUnmute(0x1194, 0x8000, 13); //  a LED shows if the INT volume adjustment is active

DcsBios::LED intFmUnmute(0x119c, 0x8000, PIN); // for the FM volume

DcsBios::LED intVhfUnmute(0x11a6, 0x0001, PIN); // for the VHF volume

and so on

 

If you are not sure for a dedicated address, you may compare it to the regular output statements.

// regular statement for the VHF volume unmute (0x11a6, 0x0001)
void onIntVhfUnmuteChange(unsigned int newValue) {
    /* your code here */
}
DcsBios::IntegerBuffer intVhfUnmuteBuffer(0x11a6, 0x0001, 0, onIntVhfUnmuteChange);

// LED address for the VHF volume unmute (0x11a6, 0x0001) same as above
DcsBios::LED intVhfUnmute(0x11a6, 0x0001, PIN);

 

For the rotaries you have to see, what works best with your setup. The rest of the code should work as expected.

You also may remove the #include "LedControl.h" statement from this sketch.

 

Have a nice weekend.

Regards, Vinc

 

Edit: find below a list of the Intercom Panel Unmute LED statements from Bort

DcsBios::LED intAimUnmute(0x11a6, 0x0004, PIN);
DcsBios::LED intFmUnmute(0x119c, 0x8000, PIN);
DcsBios::LED intIffUnmute(0x11a6, 0x0008, PIN);
DcsBios::LED intIlsUnmute(0x11a6, 0x0010, PIN);
DcsBios::LED intIntUnmute(0x1194, 0x8000, PIN);
DcsBios::LED intTcnUnmute(0x11a6, 0x0020, PIN);
DcsBios::LED intUhfUnmute(0x11a6, 0x0002, PIN);
DcsBios::LED intVhfUnmute(0x11a6, 0x0001, PIN);

 

Awesome, thanks so much Vinc. I'll give this a shot this weekend. Thanks again for your time!

Windows 10

ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO

intel i7-8700k (Not overclocked)

16 GB Ram

EVGA GeForce GTX 108ti SC Black Edition

SSD

Trackir

Posted
Am 29.11.2024 um 19:52 schrieb Kenpilot:

Awesome, thanks so much Vinc. I'll give this a shot this weekend. Thanks again for your time!

Ken, could you please publish your working sketch in the thread after you have it completed? That would be a great help for others, too.

Thank you.

Loads do it on the fly!    Loads.jpg     Royal Bavarian Airforce all the way

RIG: RYZEN 7  5800X3D~ ZOTAC 4080 Super ~ AORUS X570S Elite AX ~64 GB Corsair Venegance DDR-4 3600 ~ BeQuiet AIO Silent loop 2 360  watercooled ~ Samsung 890 Pro M.2 (2TB) + 870 EVO (1TB) SSD ~ WIN 10 64-bit ~ AOC 31.5" Gaming 144Hz Display ~ DelanClip@TrackIR 5 ~ TM Warthog no.2 ~Saitek rudder pedals~ 2 TM MFDs on 2nd 27"display ~ Buddyfox A-10 UFC ~ CDU/AAP panel via DCSBios ~ ARC-210 (soldering WIP) ~
QUEST 3 

 

Posted
On 11/29/2024 at 6:16 AM, Kenpilot said:

Thanks guys. I was curious if the LED addresses needed to be different. I'm not sure if BORT will have individual address for the LEDs as this programming isn't how it actually acts in the game. I believe the lighting for the volume names are simply panel backlighting in the game, they don't individually light up when activated in the game, that's just how I wanted to program it so I know which ones are unmuted since I don't have pop up volume controls like the actual aircraft. Any idea how else to determine or create an address for each LED? 

Or if they are controlled by their GND pin, I'll need to rewire them so they are each grounded individually instead of all being a common ground as I have them wired now.

There are some things included in DCS-BIOS that aren't in the cockpits, but the data was found to be available and useful.  e.g. weight-on-wheels indications.

AFAIK, ALL the DCS-BIOS LEDs are active-high control (5V turns it on) by default.

Posted

Thanks for all the help guys, the appropriate addresses for the LEDs did the trick and everything works great now. 

@sharkfin61 I will certainly do that, great idea. Hope it helps others!

  • Like 1

Windows 10

ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO

intel i7-8700k (Not overclocked)

16 GB Ram

EVGA GeForce GTX 108ti SC Black Edition

SSD

Trackir

  • Recently Browsing   0 members

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