FroznAK Posted April 24, 2023 Posted April 24, 2023 (edited) I acquired an authentic ARC-164(V) switching unit and decided to attempt to make it work with DCS. I'm am very new to the whole panel making and just finished my first A-10 panels (AAP, TACAN, ILS, Ext. Lighting) using PCFlights panels and Arduino's, using DCS-BIOS. It all works well, but I'd like to use the ARC-164 for multiple aircraft. My plan for the ARC-164 is to use an Arduino Pro Micro (clone) as to use it as a standard HID controller. In theory, I can use 9 analog inputs for all of the rotary switches, but my programing skills leave a lot to be desired. There are few approaches that I can take here, but I wanted to see what everyone thought would be best. I started by disassembling and cleaning the panel and working on the preset switch. This one is interesting, as it's actually 2 switches in 1. The left switch (looking from rear of panel) is for the 1st digit (0-9) and the right switch controls the 2nd digit (0-2). My plan is to wire the left switch positions into series on a pbc, with resistors between, to wire to an analog input. My question is: is there a way to also wire the right switch into series with the left, so I can use 1 input? I'm not even sure how that would work, but I have in my head it would involve a transistor or something. Or would it just be easier to wire the right switch to 1 or 2 digital inputs and program an if/else statement to control the switch state? Please keep in mind this is all theoretical in my head and I have no idea how to practically make this all work! At least I was smart enough to be able map the switches to their corresponding pins on the back of the panel on my own. lol Edited April 24, 2023 by FroznAK
FroznAK Posted April 24, 2023 Author Posted April 24, 2023 (edited) As for coding, using the Joystick.h library, this is what I got working for my test. There's got to be a better way to write this out, instead of essentially repeating the same lines of code over and over, and only changing the button that matches the analog input state. Any suggestions? // Test for ARC-164 Preset Channel Rotary Switch // Include the necessary libraries #include <Arduino.h> #include <Joystick.h> // include Joystick library // define Joystick Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, // HID report ID, default is 0x03 JOYSTICK_TYPE_GAMEPAD, // Joystick type defaults to JOYSTICK_TYPE_JOYSTICK = joystick, JOYSTICK_TYPE_GAMEPAD = gamepad, JOYSTICK_TYPE_MULTI_AXIS = multi axis controller 10, // default 32, number of buttons 0, // number of hat switches, default 2 false, // X axis false, // Y axis false, // Z axis false, // Rx axis false, // Ry axis false, // Rx axis false, // rudder axis false, // throttle axis false, // Accelerator axis false, // brake axis false); // stearing axis // Define the pin numbers for the rotary switches // UHF Preset Channel Rotary switch consists of single dial that mechanically operates 2 rotary switches // the 1's dial has 10-positions and each position will be wired in series, separated by 1K ohm resistors and connected to a single analog input const int Preset01sPin = A0; // 10-position rotary switch (analog input) // the 10's position has 3 positions (0-2), but will only use 2 digital inputs and program logic to control off state // for test purposes only use 1 pin for 2 states (on/off) const int Preset10sPin1 = 2; // 3-position rotary switch (digital input 10's) // Variables to store the current state of the switches int Preset01sSwitchValue = 0; void setup() { // Initialize the serial communication Serial.begin(9600); // Set the pin mode for the digital switch pinMode(Preset10sPin1, INPUT_PULLUP); pinMode(A0, INPUT); // Initialize Joystick Library Joystick.begin(); } void loop() { int Preset10sSwitchState = digitalRead(Preset10sPin1); // Read the current value of the analog switch Preset01sSwitchValue = analogRead(Preset01sPin); int mappedPreset01sSwitchValue = 0; if (Preset01sSwitchValue > 0) {mappedPreset01sSwitchValue = 0;} if (Preset01sSwitchValue > 245) {mappedPreset01sSwitchValue = 1;} if (Preset01sSwitchValue > 490) {mappedPreset01sSwitchValue = 2;} if (Preset01sSwitchValue > 750) {mappedPreset01sSwitchValue = 3;} if (Preset01sSwitchValue > 1010) {mappedPreset01sSwitchValue = 4;} // Map the analog value to a range of 0 to 9 // int mappedPreset01sSwitchValue = map(Preset01sSwitchValue, 0, 1023, 0, 4); // Read the current state of the digital switch if ((digitalRead(Preset10sPin1) == 0) && (mappedPreset01sSwitchValue == 0)) { Joystick.setButton(0, 1); } else { Joystick.setButton(0, 0); } if ((digitalRead(Preset10sPin1) == 0) && (mappedPreset01sSwitchValue == 1)) { Joystick.setButton(1, 1); } else { Joystick.setButton(1, 0); } if ((digitalRead(Preset10sPin1) == 0) && (mappedPreset01sSwitchValue == 2)) { Joystick.setButton(2, 1); } else { Joystick.setButton(2, 0); } if ((digitalRead(Preset10sPin1) == 0) && (mappedPreset01sSwitchValue ==3)) { Joystick.setButton(3, HIGH); } else { Joystick.setButton(3, LOW); } if ((digitalRead(Preset10sPin1) == 0) && (mappedPreset01sSwitchValue == 4)) { Joystick.setButton(4, HIGH); } else { Joystick.setButton(4, LOW); } if ((digitalRead(Preset10sPin1) == 1) && (mappedPreset01sSwitchValue == 0)) { Joystick.setButton(5, HIGH); } else { Joystick.setButton(5, LOW); } if ((digitalRead(Preset10sPin1) == 1) && (mappedPreset01sSwitchValue == 1)) { Joystick.setButton(6, HIGH); } else { Joystick.setButton(6, LOW); } if ((digitalRead(Preset10sPin1) == 1) && (mappedPreset01sSwitchValue == 2)) { Joystick.setButton(7, HIGH); } else { Joystick.setButton(7, LOW); } if ((digitalRead(Preset10sPin1) == 1) && (mappedPreset01sSwitchValue == 3)) { Joystick.setButton(8, HIGH); } else { Joystick.setButton(8, LOW); } if ((digitalRead(Preset10sPin1) == 1) && (mappedPreset01sSwitchValue == 4)) { Joystick.setButton(9, HIGH); } else { Joystick.setButton(9, LOW); } // Add a delay to avoid rapid changes in the output delay(100); Serial.print("Preset01sSwitchValue = "); Serial.print(Preset01sSwitchValue); Serial.print("; Preset10sSwitchState = "); Serial.print(Preset10sSwitchState); Serial.print("; mappedPreset01sSwitchValue = "); Serial.println(mappedPreset01sSwitchValue); delay(100); } EDIT: updated code for syntax and completeness. Edited April 26, 2023 by FroznAK
No1sonuk Posted April 24, 2023 Posted April 24, 2023 If you try to wire two switches to one input, you'll massively complicate things. Like requiring binary step resistor networks. You'll turn a 10-position switch and a 3 position switch into a 30 posiyion switch hidden in 8192 possible combinations... A 10-position switch has 2048 possible combinations if each position could be on or off. That is significantly reduced if only one can be on at a time. Add a second switch, and the numbers go higher. HOWEVER, if you only use one switch per input, you can use linear potential dividers which are easier to decode. Check out this video, but note the comment by Kinnik Kinnick about simplifying the code with a map function: 1
FroznAK Posted April 24, 2023 Author Posted April 24, 2023 3 hours ago, No1sonuk said: If you try to wire two switches to one input, you'll massively complicate things. Like requiring binary step resistor networks. You'll turn a 10-position switch and a 3 position switch into a 30 posiyion switch hidden in 8192 possible combinations... A 10-position switch has 2048 possible combinations if each position could be on or off. That is significantly reduced if only one can be on at a time. Add a second switch, and the numbers go higher. HOWEVER, if you only use one switch per input, you can use linear potential dividers which are easier to decode. Check out this video, but note the comment by Kinnik Kinnick about simplifying the code with a map function: Appreciate the reply and video. That's actually what I'm attempting to do here. I left out the map function coding for brevity. What I posted is trying to convert the map function result to a joystick button output. It gets complicated because the Preset switch has 20 FIXED combinations, based on the combined output from 2 rotaries. They are mechanically linked together. I think what I have will work, it's just not very elegant.
Recommended Posts