Jump to content

Trounce

Members
  • Posts

    50
  • Joined

  • Last visited

Everything posted by Trounce

  1. NOTE, I need to add more code, to account for resistance ladders that could be used on the ports too.
  2. I stumbled upon a code and modified it a bit to be super useful and determining the outputs/patterns of any kind of aircraft equipment that has a state of either high/low. It will also show binary/gray code. You can use this information to write new/different class states if you are using DCS-Bios. I have successfully used this code to test the outputs so far for my TACAN and ARC-164 which work in my A10C simpit. Hopefully you folks can use it too. It will not show information regarding servos or synchro's nor analog pots. But, that could be added. This code is just simply a diagnostic output reader. Connect the board to common ground, wire the pins to any random digital arduino I/O and annotate in the code. Watch the serial monitor as you flip switches to see the outputs. Now, this code only looks at 9 outputs, BUT you can add additional lines for how ever many inputs you have! Check it out: // set pin numbers to the 'const int switchPinx': const int switchPin1 = 2; // the number of the switch’s pin const int switchPin2 = 3; // the number of the switch’s pin const int switchPin3 = 4; // the number of the switch’s pin const int switchPin4 = 5; // the number of the switch’s pin const int switchPin5 = 6; // the number of the switch’s pin const int switchPin6 = 7; // the number of the switch’s pin const int switchPin7 = 8; // the number of the switch’s pin const int switchPin8 = 9; // the number of the switch’s pin const int switchPin9 = 10; // the number of the switch’s pin // set variables: int switchState1 = 0; // variable for reading the switch’s status int switchState2 = 0; // variable for reading the switch’s status int switchState3 = 0; // variable for reading the switch’s status int switchState4 = 0; // variable for reading the switch’s status int switchState5 = 0; // variable for reading the switch's status int switchState6 = 0; // variable for reading the switch’s status int switchState7 = 0; // variable for reading the switch’s status int switchState8 = 0; // variable for reading the switch’s status int switchState9 = 0; // variable for reading the switch’s status byte test = B0000; // Variable for printing value over serial debug void setup() { // Start serial debugging… Serial.begin(250000); // initialize the switch pins as an input: pinMode(switchPin1, INPUT); pinMode(switchPin2, INPUT); pinMode(switchPin3, INPUT); pinMode(switchPin4, INPUT); pinMode(switchPin5, INPUT); pinMode(switchPin6, INPUT); pinMode(switchPin7, INPUT); pinMode(switchPin8, INPUT); pinMode(switchPin9, INPUT); } void loop(){ // read the state of the switch’s individual pins: switchState1 = digitalRead(switchPin1); switchState2 = digitalRead(switchPin2); switchState3 = digitalRead(switchPin3); switchState4 = digitalRead(switchPin4); switchState5 = digitalRead(switchPin5); switchState6 = digitalRead(switchPin6); switchState7 = digitalRead(switchPin7); switchState8 = digitalRead(switchPin8); switchState9 = digitalRead(switchPin9); // If the output state is high, the serial monitor will show HIGH. If not, it will show --- if (switchState1 == HIGH) { Serial.println("switchState1 ON"); } else { Serial.println("switchState1 ---"); } if (switchState2 == HIGH) { Serial.println("siwtchState2 ON"); } else { Serial.println("switchState2 ---"); } if (switchState3 == HIGH) { Serial.println("switchState3 ON"); } else { Serial.println("switchState3 ---"); } if (switchState4 == HIGH) { Serial.println("switchState4 ON"); } else { Serial.println("switchState4 ---"); } if (switchState5 == HIGH) { Serial.println("switchState5 ON"); } else { Serial.println("switchState5 ---"); } if (switchState6 == HIGH) { Serial.println("siwtchState6 ON"); } else { Serial.println("switchState6 ---"); } if (switchState7 == HIGH) { Serial.println("switchState7 ON"); } else { Serial.println("switchState7 ---"); } if (switchState8 == HIGH) { Serial.println("switchState8 ON"); } else { Serial.println("switchState8 ---"); } if (switchState9 == HIGH) { Serial.println("switchState9 ON"); } else { Serial.println("switchState9 ---"); } Serial.println("\n"); delay(2000); }
  3. About the code above, it seems that my preset selector switch might be busted, so I can only get 15 working channels out of it. Pin 4 always seems to be shorted to ground, so I can only get 16 bits of data 0-15 instead of the full 32 bits. Meh, 15 channels is completely usable and I'm happy. Hardware: Arduino Mega (knockoff). Max2719 (for Common Cathode LED display) with resistor of 30K, two parallel capacitors of 10uF and 10nF. I got the LED's displays from ebay. They are 3 digit displays common cathode. The windows with the original display had to be slightly filed to accommodate these LED displays, but careful and slow filing with a jewelers file will do the trick nicely.
  4. Well, I am happy with 15 preset channels working. I actually think the switch pin 4 might have a short since it's always tied to ground (internally in the switch itself). Oh well. I'm going to call the case closed and run with 15. Thanks!
  5. This is my short album for some pics of my radio: https://imgur.com/a/HIs1K Here is the code I use to make the switches work. NOTE, I did not set the zero swithc, load, cover, status, test display or volume (I plan on doing the volume though). My wires aren't in any special order because I cable clustered them. I think I need to tidy it up a bit better, but it all works though. #define DCSBIOS_IRQ_SERIAL #include "DcsBios.h" #include <LedControl.h> /* This code is used on the Arduino Mega */ namespace DcsBios { /* This is the begining of the code for the new switch class for the UHF Preset Select switch */ class Switch20Pos : PollingInput { private: const char* msg_; char pinA_; char pinB_; char pinC_; char pinD_; char pinE_; char lastState_; char readState() { /* set pin numbers: */ const int switchPin1 = A1; // the number of the switch’s pin const int switchPin2 = A2; const int switchPin3 = A3; const int switchPin4 = A4; const int switchPin5 = A5; /* set variables: */ int switchState1 = 0; // variable for reading the switch’s status int switchState2 = 0; int switchState3 = 0; int switchState4 = 0; int switchState5 = 0; switchState1 = digitalRead(switchPin1); switchState2 = digitalRead(switchPin2); switchState3 = digitalRead(switchPin3); switchState4 = digitalRead(switchPin4); switchState5 = digitalRead(switchPin5); /*Channel*/ /*Logic Table*/ /*01*/ if (((switchState1 && switchState2 && switchState3 && switchState4) == HIGH ) && (switchState5 == LOW)) return 1; /*02*/ if (((switchState1 && switchState3 && switchState4) == HIGH ) && ((switchState2 or switchState5 ) == LOW)) return 2; /*03*/ if (((switchState1 && switchState3 && switchState4 && switchState5) == HIGH) && (switchState2 == LOW)) return 3; /*04*/ if (((switchState1 && switchState4 && switchState5) == HIGH) && ((switchState2 or switchState3)== LOW)) return 4; /*05*/ if (((switchState1 && switchState4) == HIGH) && ((switchState2 or switchState3 or switchState5)== LOW)) return 5; /*06*/ if (((switchState1 && switchState2 && switchState4) == HIGH) && ((switchState3 or switchState5)== LOW)) return 6; /*07*/ if (((switchState1 && switchState2 && switchState4 && switchState5) == HIGH) && (switchState3 == LOW)) return 7; /*08*/ if (((switchState2 && switchState4 && switchState5) == HIGH) && ((switchState1 or switchState3)== LOW)) return 8; /*09*/ if (((switchState2 && switchState4) == HIGH) && ((switchState1 or switchState3 or switchState5)== LOW)) return 9; /*10*/ if ((switchState4 == HIGH) && ((switchState1 or switchState2 or switchState3 or switchState5)== LOW)) return 10; /*11*/ if (((switchState4 && switchState5)== HIGH) && ((switchState1 or switchState2 or switchState3)== LOW)) return 11; /*12*/ if (((switchState3 && switchState4 && switchState5)== HIGH) && ((switchState1 or switchState2)== LOW)) return 12; /*13*/ if (((switchState3 && switchState4)== HIGH) && ((switchState1 or switchState2 or switchState5)== LOW)) return 13; /*14*/ if (((switchState2 && switchState3 && switchState4)== HIGH) && ((switchState1 or switchState5)== LOW)) return 14; /*15*/ if (((switchState2 && switchState3 && switchState4 && switchState5)== HIGH) && (switchState1 == LOW)) return 15; return 00; } void pollInput() { char state = readState(); if (state != lastState_) { if (state == 0) if (tryToSendDcsBiosMessage(msg_, "0")) lastState_ = state; if (state == 1) if (tryToSendDcsBiosMessage(msg_, "1")) lastState_ = state; if (state == 2) if (tryToSendDcsBiosMessage(msg_, "2")) lastState_ = state; if (state == 3) if (tryToSendDcsBiosMessage(msg_, "3")) lastState_ = state; if (state == 4) if (tryToSendDcsBiosMessage(msg_, "4")) lastState_ = state; if (state == 5) if (tryToSendDcsBiosMessage(msg_, "5")) lastState_ = state; if (state == 6) if (tryToSendDcsBiosMessage(msg_, "6")) lastState_ = state; if (state == 7) if (tryToSendDcsBiosMessage(msg_, "7")) lastState_ = state; if (state == 8) if (tryToSendDcsBiosMessage(msg_, "8")) lastState_ = state; if (state == 9) if (tryToSendDcsBiosMessage(msg_, "9")) lastState_ = state; if (state == 10) if (tryToSendDcsBiosMessage(msg_, "10")) lastState_ = state; if (state == 11) if (tryToSendDcsBiosMessage(msg_, "11")) lastState_ = state; if (state == 12) if (tryToSendDcsBiosMessage(msg_, "12")) lastState_ = state; if (state == 13) if (tryToSendDcsBiosMessage(msg_, "13")) lastState_ = state; if (state == 14) if(tryToSendDcsBiosMessage(msg_, "14")) lastState_ = state; if (state == 15) if (tryToSendDcsBiosMessage(msg_, "15")) lastState_ = state; if (state == 16) if (tryToSendDcsBiosMessage(msg_, "16")) lastState_ = state; if (state == 17) if (tryToSendDcsBiosMessage(msg_, "17")) lastState_ = state; if (state == 18) if (tryToSendDcsBiosMessage(msg_, "18")) lastState_ = state; if (state == 19) if(tryToSendDcsBiosMessage(msg_, "19")) lastState_ = state; } } public: Switch20Pos(const char* msg, char pinA, char pinB, char pinC, char pinD, char pinE) { msg_ = msg; pinA_ = pinA; pinB_ = pinB; pinC_ = pinC; pinD_ = pinD; pinE_ = pinE; pinMode(pinA_, INPUT_PULLUP); pinMode(pinB_, INPUT_PULLUP); pinMode(pinC_, INPUT_PULLUP); pinMode(pinD_, INPUT_PULLUP); pinMode(pinE_, INPUT_PULLUP); lastState_ = readState(); } }; } /* This concludes the code for the new 20 position switch for the UHF Preset Selector Switch */ // inputs: DIN pin, CLK pin, LOAD pin. number of chips LedControl lc = LedControl(9, 11, 10, 1); /* These are on the PWM output on the Mega, it's okay to use them */ // lc.setChar(0, 6, 3, false); //lc.setChar(0, 7, 2, false); void onUhfFrequencyChange(char* newValue) { /*UHF display*/ /* 0,1 = first MAX2719, digit to writ to on MAX2719 output; [0] is the first digit DCS transmits for the display */ lc.setChar(0,1,newValue[0], false); /*DIGIT 1 "0,1" should have been digit "0,0" but I soldered to wrong max2719 pin for digit 1 instead of digit 0 on the chip. */ lc.setChar(0,2,newValue[1], false); lc.setChar(0,3,newValue[2], true); lc.setChar(0,4,newValue[2], false); lc.setChar(0,4,newValue[4], false); lc.setChar(0,5,newValue[5], false); lc.setChar(0,6,newValue[6], false); } DcsBios::StringBuffer<7> uhfFrequencyBuffer(0x1180, onUhfFrequencyChange); /*Channel presets*/ void onUhfPresetChange(char* newValue) { lc.setChar(0,7,newValue[0], false); lc.setChar(0,0,newValue[1], false); /*I just wrote the code to reuse digit 0 on the MAX2719 chip for the UHF Preset channel selector instead */ } DcsBios::StringBuffer<2> uhfPresetBuffer(0x1188, onUhfPresetChange); void onUhfPresetSelChange(char* newValue) { } DcsBios::StringBuffer<2> uhfPresetSelStrBuffer(0x1176, onUhfPresetSelChange); /* ******VALIDATED LINE INCLUDING PINS, I soldered the pins and plugged them in randomly. Use serial monitor to see which ones are wired where. ****** */ const byte uhf10mhzSelPins[10] = {38, 40, 34, 42, 36, 46, 52, 50, 44, 48,}; DcsBios::SwitchMultiPos uhf10mhzSel("UHF_10MHZ_SEL", uhf10mhzSelPins, 10); /* ******VALIDATED LINE INCLUDING PINS****** */ const byte uhf1mhzSelPins[10] = {37, 53, 47, 45, 49, 43, 51, 39, 41, 35}; DcsBios::SwitchMultiPos uhf1mhzSel("UHF_1MHZ_SEL", uhf1mhzSelPins, 10); /* ******VALIDATED LINE INCLUDING PINS****** */ const byte uhfPoint1mhzSelPins[10] = {31, 26, 29, 27, 22, 30, 25, 24, 28, 23,}; DcsBios::SwitchMultiPos uhfPoint1mhzSel("UHF_POINT1MHZ_SEL", uhfPoint1mhzSelPins, 10); /* ******VALIDATED LINE INCLUDING PINS****** */ DcsBios::Switch3Pos uhfTTone("UHF_T_TONE", A10, A9); /*!!!!!!!!!!!!!!! not not NOT not NOT VALIDATED */ const byte uhf100mhzSelPins[3] = {5, 6, 7}; DcsBios::SwitchMultiPos uhf100mhzSel("UHF_100MHZ_SEL", uhf100mhzSelPins, 3); /* ******VALIDATED LINE INCLUDING PINS****** */ const byte uhfPoint25SelPins[4] = {2, 8, 4, 3}; DcsBios::SwitchMultiPos uhfPoint25Sel("UHF_POINT25_SEL", uhfPoint25SelPins, 4); const byte uhfFunctionPins[4] = {17, 14, 16, 15}; DcsBios::SwitchMultiPos uhfFunction("UHF_FUNCTION", uhfFunctionPins, 4); DcsBios::Switch3Pos uhfMode("UHF_MODE", 20, 19); DcsBios::Switch2Pos uhfSquelch("UHF_SQUELCH", A8); DcsBios::Switch20Pos uhfPresetSel("UHF_PRESET_SEL", A1, A2, A3, A4, A5); void setup() { DcsBios::setup(); //This initializes the MAX7219 and gets it ready of use: lc.shutdown(0,false); //turn on the display lc.setIntensity(0,8);//set the brightness lc.clearDisplay(0); //clear the display } void loop() { DcsBios::loop(); } Also, if you look closely, I broke the traces on the PCB.
  6. Hold your horses FragBum, I was sober when I wired this up. I am getting my sauce on now and I'm going to start tinkering.
  7. Okay. I has having some code difficulties where channel 16 should start. So I re-wired my pins to be in order now to make it easier to distill. I have a code that I use to view the logic and write the logic tables before implementing them in DCS-Bios for the switch I want to share with you all. This logic table can be used for binary/gray code: // This code will show you what pins are outputting on the analog pins that you want to use your ARC-164 Preset selector on // This code is designed to help you see the pins to write your logic table while in serial monitor // after finding out the logic table that works for you, you can implement the Switch20Pos class that I built with your logic table // set pin numbers: const int switchPin1 = A1; // the number of the switch’s pin const int switchPin2 = A2; // the number of the switch’s pin const int switchPin3 = A3; // the number of the switch’s pin const int switchPin4 = A4; // the number of the switch’s pin const int switchPin5 = A5; // set variables: int switchState1 = 0; // variable for reading the switch’s status int switchState2 = 0; // variable for reading the switch’s status int switchState3 = 0; // variable for reading the switch’s status int switchState4 = 0; // variable for reading the switch’s status int switchState5 = 0; // variable for reading the switch’s status void setup() { // Start serial debugging… Serial.begin(250000); // initialize the switch pins as an input: // sets the analog pins to High pinMode(switchPin1, INPUT); digitalWrite(A1,HIGH); pinMode(switchPin2, INPUT); digitalWrite(A2,HIGH); pinMode(switchPin3, INPUT); digitalWrite(A3,HIGH); pinMode(switchPin4, INPUT); digitalWrite(A4,HIGH); pinMode(switchPin5, INPUT); digitalWrite(A5,HIGH); } void loop(){ // read the state of the switch’s individual pins: switchState1 = digitalRead(switchPin1); switchState2 = digitalRead(switchPin2); switchState3 = digitalRead(switchPin3); switchState4 = digitalRead(switchPin4); switchState5 = digitalRead(switchPin5); // The next code will show all 5 switch states in serial monitor and which ones are on/off. if (switchState1 == HIGH) { Serial.println("switchState1 ON"); } else { Serial.println("switchState1 ---"); } if (switchState2 == HIGH) { Serial.println("siwtchState2 ON"); } else { Serial.println("switchState2 ---"); } if (switchState3 == HIGH) { Serial.println("switchState3 ON"); } else { Serial.println("switchState3 ---"); } if (switchState4 == HIGH) { Serial.println("switchState4 ON"); } else { Serial.println("switchState4 ---"); } if (switchState5 == HIGH) { Serial.println("switchState5 ON"); } else { Serial.println("switchState5 ---"); } //This next code is where you will build your logic table //The logic table below is for my switch and may differ a little from yours. Just plug and play around //Channel 1 if (((switchState1 && switchState2 && switchState3 && switchState4) == HIGH ) && (switchState5 == LOW)){ Serial.println("Channel 1 ON"); } else { Serial.println("Channel 1 ---"); } //Channel 2 /*VALIDATED!!!!!! */ if (( (switchState1 && switchState3 && switchState4) == HIGH ) && ((switchState2 or switchState5 ) == LOW)) { Serial.println("Channel 2 ON"); } else { Serial.println("Channel 2 ---"); } //Channel 3 /*VALIDATED!!!!!! */ if (((switchState1 && switchState3 && switchState4 && switchState5) == HIGH) && (switchState2 == LOW)) { Serial.println("Channel 3 ON"); } else { Serial.println("Channel 3 ---");// } //Channel 4 /*VALIDATED!!!!!! */ if (((switchState1 && switchState4 && switchState5) == HIGH) && ((switchState2 or switchState3)== LOW)) { Serial.println("Channel 4 ON"); } else { Serial.println("Channel 4 ---"); } //Channel 5 /*VALIDATED!!!!!! */ if (((switchState1 && switchState4) == HIGH) && ((switchState2 or switchState3 or switchState5)== LOW)) { Serial.println("Channel 5 ON"); } else { Serial.println("Channel 5 ---"); } //Channel 6 /*VALIDATED!!!!!! */ if (((switchState1 && switchState2 && switchState4) == HIGH) && ((switchState3 or switchState5)== LOW)) { Serial.println("Channel 6 ON"); } else { Serial.println("Channel 6 ---"); } //Channel 7 /*VALIDATED!!!!!! */ if (((switchState1 && switchState2 && switchState4 && switchState5) == HIGH) && (switchState3 == LOW)) { Serial.println("Channel 7 ON"); } else { Serial.println("Channel 7 ---"); } //Channel 8 /*VALIDATED!!!!!! */ if (((switchState2 && switchState4 && switchState5) == HIGH) && ((switchState1 or switchState3)== LOW)) { Serial.println("Channel 8 ON"); } else { Serial.println("Channel 8 ---"); } //Channel 9 /*VALIDATED!!!!!! */ if (((switchState2 && switchState4) == HIGH) && ((switchState1 or switchState3 or switchState5)== LOW)) { Serial.println("Channel 9 ON"); } else { Serial.println("Channel 9 ---"); } //Channel 10 /*VALIDATED!!!!!! */ if ((switchState4 == HIGH) && ((switchState1 or switchState2 or switchState3 or switchState5)== LOW)) { Serial.println("Channel 10 ON"); } else { Serial.println("Channel 10 ---"); } //Channel 11 /*VALIDATED!!!!!! */ if (((switchState4 && switchState5)== HIGH) && ((switchState1 or switchState2 or switchState3)== LOW)) { Serial.println("Channel 11 ON"); } else { Serial.println("Channel 11 ---"); } //Channel 12 /*VALIDATED!!!!!! */ if (((switchState3 && switchState4 && switchState5)== HIGH) && ((switchState1 or switchState2)== LOW)) { Serial.println("Channel 12 ON"); } else { Serial.println("Channel 12 ---"); } //Channel 13 /*VALIDATED!!!!!! */ if (((switchState3 && switchState4)== HIGH) && ((switchState1 or switchState2 or switchState5)== LOW)) { Serial.println("Channel 13 ON"); } else { Serial.println("Channel 13 ---"); } //Channel 14 /*VALIDATED!!!!!! */ if (((switchState2 && switchState3 && switchState4)== HIGH) && ((switchState1 or switchState5)== LOW)) { Serial.println("Channel 14 ON"); } else { Serial.println("Channel 14 ---"); } //Channel 15 /*VALIDATED!!!!!! */ if (((switchState2 && switchState3 && switchState4 && switchState5)== HIGH) && (switchState1 == LOW)) { Serial.println("Channel 15 ON"); } else { Serial.println("Channel 15 ---"); } // from this point on channels that should be 16-20 do not reflect correctly on my switch; // the preset selector starts counting backwards when it should be on channel 16 example: Still good ==>13, 14, 15, 15*(bugged now)===>(should be 16), 14(17) 13(18) 12(19) 11(20) // the only possibility I can think of is that I may have not counted on another pin somewhere, maybe a surface mount at the base of the switch? Serial.println("\n"); delay(2000); }
  8. SUCCESS!!!!!!!! So, it's super messed up code probably, but it 100% works. Heh, after 52oz of scotch I got it to work. I saved it and on putting it on here for posterity. I used Boolean with and wrote a new switch class as well. It only works up to channel 10 so far, because I have to plot the last 10 channels 11-20 truth table tomorrow. To easy! Now, all my ARC-164 switches work. Check out this new switch class and Boolean for the gray code (NOTE, this code contains all programs for my switches. It takes an almost an entire Arduino Mega to run an ARC-164 face plate) (additional note for others wanting to use this... my wires aren't in order in anyway, you just have to change the pin numbers to correspond to the ones YOU are using): #define DCSBIOS_IRQ_SERIAL #include "DcsBios.h" #include <LedControl.h> /* This code is used on the Arduino Mega */ namespace DcsBios { class Switch20Pos : PollingInput { private: const char* msg_; char pinA_; char pinB_; char pinC_; char pinD_; char pinE_; char lastState_; char readState() { // set pin numbers: const int switchPin1 = A2; // the number of the switch’s pin const int switchPin2 = A6; // the number of the switch’s pin const int switchPin3 = A3; // the number of the switch’s pin const int switchPin4 = A1; // the number of the switch’s pin const int switchPin5 = A5; // set variables: int switchState1 = 0; // variable for reading the switch’s status int switchState2 = 0; // variable for reading the switch’s status int switchState3 = 0; // variable for reading the switch’s status int switchState4 = 0; // variable for reading the switch’s status int switchState5 = 0; switchState1 = digitalRead(switchPin1); switchState2 = digitalRead(switchPin2); switchState3 = digitalRead(switchPin3); switchState4 = digitalRead(switchPin4); switchState5 = digitalRead(switchPin5); if (((switchState1 && switchState2 && switchState3 && switchState4) == HIGH ) && (switchState5 == LOW))return 1; if (((switchState1 && switchState3 && switchState4) == HIGH ) && ((switchState2 or switchState5 ) == LOW)) return 2; if (((switchState1 && switchState3 && switchState4 && switchState5) == HIGH) && (switchState2 == LOW)) return 3; if (((switchState1 && switchState4 && switchState5) == HIGH) && ((switchState2 or switchState3)== LOW)) return 4; if (((switchState1 && switchState4) == HIGH) && ((switchState2 or switchState3 or switchState5)== LOW)) return 5; if (((switchState1 && switchState2 && switchState4) == HIGH) && ((switchState3 or switchState5)== LOW)) return 6; if (((switchState1 && switchState2 && switchState4 && switchState5) == HIGH) && (switchState3 == LOW)) return 7; if (((switchState1 && switchState2 && switchState5) == HIGH) && ((switchState3 or switchState4)== LOW)) return 8; if (((switchState1 && switchState2) == HIGH) && ((switchState3 or switchState4 or switchState5)== LOW)) return 9; if ((switchState1 == HIGH) && ((switchState2 or switchState3 or switchState4 or switchState5)== LOW)) return 10; return 4; } void pollInput() { char state = readState(); if (state != lastState_) { if (state == 0) if (tryToSendDcsBiosMessage(msg_, "0")) lastState_ = state; if (state == 1) if (tryToSendDcsBiosMessage(msg_, "1")) lastState_ = state; if (state == 2) if (tryToSendDcsBiosMessage(msg_, "2")) lastState_ = state; if (state == 3) if (tryToSendDcsBiosMessage(msg_, "3")) lastState_ = state; if (state == 4) if (tryToSendDcsBiosMessage(msg_, "4")) lastState_ = state; if (state == 5) if (tryToSendDcsBiosMessage(msg_, "5")) lastState_ = state; if (state == 6) if (tryToSendDcsBiosMessage(msg_, "6")) lastState_ = state; if (state == 7) if (tryToSendDcsBiosMessage(msg_, "7")) lastState_ = state; if (state == 8) if (tryToSendDcsBiosMessage(msg_, "8")) lastState_ = state; if (state == 9) if (tryToSendDcsBiosMessage(msg_, "9")) lastState_ = state; if (state == 10) if (tryToSendDcsBiosMessage(msg_, "10")) lastState_ = state; if (state == 11) if (tryToSendDcsBiosMessage(msg_, "11")) lastState_ = state; if (state == 12) if (tryToSendDcsBiosMessage(msg_, "12")) lastState_ = state; if (state == 13) if (tryToSendDcsBiosMessage(msg_, "13")) lastState_ = state; if (state == 14) if(tryToSendDcsBiosMessage(msg_, "14")) lastState_ = state; if (state == 15) if (tryToSendDcsBiosMessage(msg_, "15")) lastState_ = state; if (state == 16) if (tryToSendDcsBiosMessage(msg_, "16")) lastState_ = state; if (state == 17) if (tryToSendDcsBiosMessage(msg_, "17")) lastState_ = state; if (state == 18) if (tryToSendDcsBiosMessage(msg_, "18")) lastState_ = state; if (state == 19) if(tryToSendDcsBiosMessage(msg_, "19")) lastState_ = state; } } public: Switch20Pos(const char* msg, char pinA, char pinB, char pinC, char pinD, char pinE) { msg_ = msg; pinA_ = pinA; pinB_ = pinB; pinC_ = pinC; pinD_ = pinD; pinE_ = pinE; pinMode(pinA_, INPUT_PULLUP); pinMode(pinB_, INPUT_PULLUP); pinMode(pinC_, INPUT_PULLUP); pinMode(pinD_, INPUT_PULLUP); pinMode(pinE_, INPUT_PULLUP); lastState_ = readState(); } }; } // inputs: DIN pin, CLK pin, LOAD pin. number of chips LedControl lc = LedControl(9, 11, 10, 1); /* These are on the PWM output on the Mega, it's okay to use them */ // lc.setChar(0, 6, 3, false); //lc.setChar(0, 7, 2, false); void onUhfFrequencyChange(char* newValue) { /*UHF display*/ /* 0,1 = first MAX2719, digit to writ to on MAX2719 output; [0] is the first digit DCS transmits for the display */ lc.setChar(0,1,newValue[0], false); /*DIGIT 1 "0,1" should have been digit "0,0" but I soldered to wrong max2719 pin for digit 1 instead of digit 0 on the chip. */ lc.setChar(0,2,newValue[1], false); lc.setChar(0,3,newValue[2], true); lc.setChar(0,4,newValue[2], false); lc.setChar(0,4,newValue[4], false); lc.setChar(0,5,newValue[5], false); lc.setChar(0,6,newValue[6], false); } DcsBios::StringBuffer<7> uhfFrequencyBuffer(0x1180, onUhfFrequencyChange); /*Channel presets*/ void onUhfPresetChange(char* newValue) { lc.setChar(0,7,newValue[0], false); lc.setChar(0,0,newValue[1], false); /*I just wrote the code to reuse digit 0 on the MAX2719 chip for the UHF Preset channel selector instead */ } DcsBios::StringBuffer<2> uhfPresetBuffer(0x1188, onUhfPresetChange); void onUhfPresetSelChange(char* newValue) { } DcsBios::StringBuffer<2> uhfPresetSelStrBuffer(0x1176, onUhfPresetSelChange); /* ******VALIDATED LINE INCLUDING PINS, I soldered the pins and plugged them in randomly. Use serial monitor to see which ones are wired where. ****** */ const byte uhf10mhzSelPins[10] = {38, 40, 34, 42, 36, 46, 52, 50, 44, 48,}; DcsBios::SwitchMultiPos uhf10mhzSel("UHF_10MHZ_SEL", uhf10mhzSelPins, 10); /* ******VALIDATED LINE INCLUDING PINS****** */ const byte uhf1mhzSelPins[10] = {37, 53, 47, 45, 49, 43, 51, 39, 41, 35}; DcsBios::SwitchMultiPos uhf1mhzSel("UHF_1MHZ_SEL", uhf1mhzSelPins, 10); /* ******VALIDATED LINE INCLUDING PINS****** */ const byte uhfPoint1mhzSelPins[10] = {31, 26, 29, 27, 22, 30, 25, 24, 28, 23,}; DcsBios::SwitchMultiPos uhfPoint1mhzSel("UHF_POINT1MHZ_SEL", uhfPoint1mhzSelPins, 10); /* ******VALIDATED LINE INCLUDING PINS****** */ DcsBios::Switch3Pos uhfTTone("UHF_T_TONE", A10, A9); /*!!!!!!!!!!!!!!! not not NOT not NOT VALIDATED */ const byte uhf100mhzSelPins[3] = {5, 6, 7}; DcsBios::SwitchMultiPos uhf100mhzSel("UHF_100MHZ_SEL", uhf100mhzSelPins, 3); /* ******VALIDATED LINE INCLUDING PINS****** */ const byte uhfPoint25SelPins[4] = {2, 8, 4, 3}; DcsBios::SwitchMultiPos uhfPoint25Sel("UHF_POINT25_SEL", uhfPoint25SelPins, 4); const byte uhfFunctionPins[4] = {17, 14, 16, 15}; DcsBios::SwitchMultiPos uhfFunction("UHF_FUNCTION", uhfFunctionPins, 4); DcsBios::Switch3Pos uhfMode("UHF_MODE", 20, 19); DcsBios::Switch2Pos uhfSquelch("UHF_SQUELCH", A8); DcsBios::Switch20Pos uhfPresetSel("UHF_PRESET_SEL", A2, A6, A3, A1, A5); void setup() { DcsBios::setup(); //This initializes the MAX7219 and gets it ready of use: lc.shutdown(0,false); //turn on the display lc.setIntensity(0,8);//set the brightness lc.clearDisplay(0); //clear the display } void loop() { DcsBios::loop(); }
  9. Well Gray code is kicking my A**. I am not going to try and think about this for the rest of tonight. My attempts to code is trial and error plugging things in here and there without to much knowledge of what I'm doing until it works somehow, heh.
  10. When I plug this code directly into the Arduino compiler, I get sad panda: 'tryToSendDcsBiosMessage' was not declared in this scope <Edit> Found out what was up after playing with the library. Yep, I added this to the actual library instead of the compiler for now. In your line of code above, you have: if (tryToSendDcsBiosMessage(msg_, buf)) All the other switches use the following: if (sendDcsBiosMessage(msg_, buf)) After I changed to the later one to mimic the other switches in the library, it finally compiles and reads my switch, all twenty positions! BUT, it reads it in binary instead of Gray code (my preset values are not correct on serial monitor), so I got that going for me. I will figure this out by the weekend! Thanks!!!!
  11. DCS Bios libraries for Arduino. Good question, I think it is part of the DCS-Bios libraries for Arduino.
  12. As it stands, the only available input types for the UHF Preset in DCS Bios is with a rotary encoder or set pins: DcsBios::RotaryEncoder uhfPresetSel("UHF_PRESET_SEL", "DEC", "INC", PIN_A, PIN_B); and const byte uhfPresetSelPins[21] = {PIN_0, PIN_1, PIN_2, PIN_3, PIN_4, PIN_5, PIN_6, PIN_7, PIN_8, PIN_9, PIN_10, PIN_11, PIN_12, PIN_13, PIN_14, PIN_15, PIN_16, PIN_17, PIN_18, PIN_19, PIN_20}; DcsBios::SwitchMultiPos uhfPresetSel("UHF_PRESET_SEL", uhfPresetSelPins, 21); Don't know how to incorporate the port unless a whole new read class() is made possibly in DCS-Bios
  13. I have the 6 switch ports connected as follows: Pin 1 Common to ground Pin 2 to A2 Pin 3 to A6 Pin 4 to A3 Pin 5 to A1 Pin 6 to A5 I know, I know, what is the reason behind the pins not being in any order? Well, I had a cable cluster and that's just how they ended up on the Mega after I plugged them in. No biggie, though. I only have 8 pins left open on the Mega, the ARC-164 switches use almost all of them. <edit> This is all on Port F of the Arduino Mega
  14. Below is the SwitchMultiPos code for DCS-Bios. Can you fellows help me write a new switch class that can be used with the Gray code switches? class SwitchMultiPos : PollingInput { private: const char* msg_; const byte* pins_; char numberOfPins_; char lastState_; char readState() { unsigned char i; for (i=0; i<numberOfPins_; i++) { if (digitalRead(pins_[i]) == LOW) return i; } return lastState_; } void pollInput() { char state = readState(); if (state != lastState_) { char buf[7]; utoa(state, buf, 10); if (tryToSendDcsBiosMessage(msg_, buf)) lastState_ = state; } } public: SwitchMultiPos(const char* msg, const byte* pins, char numberOfPins) : lastState_(0) { msg_ = msg; pins_ = pins; numberOfPins_ = numberOfPins; unsigned char i; for (i=0; i<numberOfPins; i++) { pinMode(pins[i], INPUT_PULLUP); } lastState_ = readState(); } };
  15. I do not know that that means. But maybe soon, I might learn. Programming is a slow concept for me.
  16. Boltz, I think you are right after looking at my truth table for the switch compared to wikipedia Gray code. The ARC-164 preset channel switch is a 5 digit Gray code. Pretty cool and I understand now why they would use it instead of normal binary.
  17. Arghhh my brain is decomposing from this coding. I am going to shelve it till the weekend and see if a break can help out. I tried to re-upload my saved sketch and it is doing something different today.
  18. Okay this weekend I will take a picture because I have to dissasemble the radio. It is a real ARC-164 which is probably why the switch is weird. I am 100% sure that I will have to write a brand new switch class for this type of switch. It has 5 pins and they ouput twenty different combinations (1 combination for each preset channel) tied to the common. Since the outputs are NOT binary the nee class will have to be able to read boolean table mad for it. It is a real channel preset switch.
  19. So I have done the above code, up to switch position 10 and now it's time to eat dinner. Super happy with what little progress I have made. Now if anyone can help me with incorporating those "IF" statements into something useful for DCS Bios UHF Preset selector, that would be super great. If not, and I find out how, I will post it!
  20. // set pin numbers: const int switchPin1 = A2; // the number of the switch’s pin const int switchPin2 = A6; // the number of the switch’s pin const int switchPin3 = A3; // the number of the switch’s pin const int switchPin4 = A1; // the number of the switch’s pin const int switchPin5 = A5; // set variables: int switchState1 = 0; // variable for reading the switch’s status int switchState2 = 0; // variable for reading the switch’s status int switchState3 = 0; // variable for reading the switch’s status int switchState4 = 0; // variable for reading the switch’s status int switchState5 = 0; byte test = B0000; // Variable for printing value over serial debug void setup() { // Start serial debugging… Serial.begin(250000); // initialize the switch pins as an input: pinMode(switchPin1, INPUT); digitalWrite(A2,HIGH); pinMode(switchPin2, INPUT); digitalWrite(A6,HIGH); pinMode(switchPin3, INPUT); digitalWrite(A3,HIGH); pinMode(switchPin4, INPUT); digitalWrite(A1,HIGH); pinMode(switchPin5, INPUT); digitalWrite(A5,HIGH); } void loop(){ // read the state of the switch’s individual pins: switchState1 = digitalRead(switchPin1); switchState2 = digitalRead(switchPin2); switchState3 = digitalRead(switchPin3); switchState4 = digitalRead(switchPin4); switchState5 = digitalRead(switchPin5); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (switchState1 == HIGH) { Serial.println("switchState1 ON"); } else { Serial.println("switchState1 ---"); } if (switchState2 == HIGH) { Serial.println("siwtchState2 ON"); } else { Serial.println("switchState2 ---"); } if (switchState3 == HIGH) { Serial.println("switchState3 ON"); } else { Serial.println("switchState3 ---"); } if (switchState4 == HIGH) { Serial.println("switchState4 ON"); } else { Serial.println("switchState4 ---"); } if (switchState5 == HIGH) { Serial.println("switchState5 ON"); } else { Serial.println("switchState5 ---"); } //Channel 1 if (( (switchState1 && switchState2 && switchState3 && switchState4) == HIGH ) && (switchState5 == LOW)){ Serial.println("Channel 1 ON"); } else { Serial.println("Channel 1 ---"); } //Channel 2 /*VALIDATED!!!!!! */ if (( (switchState1 && switchState3 && switchState4) == HIGH ) && ((switchState2 or switchState5 ) == LOW)) { Serial.println("Channel 2 ON"); } else { Serial.println("Channel 2 ---"); } //Channel 3 /*VALIDATED!!!!!! */ if (((switchState1 && switchState3 && switchState4 && switchState5) == HIGH) && (switchState2 == LOW)) { Serial.println("Channel 3 ON"); } else { Serial.println("Channel 3 ---");// } //Channel 4 /*VALIDATED!!!!!! */ if (((switchState1 && switchState4 && switchState5) == HIGH) && ((switchState2 or switchState3)== LOW)) { Serial.println("Channel 4 ON"); } else { Serial.println("Channel 4 ---"); } //Channel 5 /*VALIDATED!!!!!! */ if (((switchState1 && switchState4) == HIGH) && ((switchState2 or switchState3 or switchState5)== LOW)) { Serial.println("Channel 5 ON"); } else { Serial.println("Channel 5 ---"); } //Channel 6 /*VALIDATED!!!!!! */ if (((switchState1 && switchState2 && switchState4) == HIGH) && ((switchState3 or switchState5)== LOW)) { Serial.println("Channel 6 ON"); } else { Serial.println("Channel 6 ---"); } //Channel 7 /*VALIDATED!!!!!! */ if (((switchState1 && switchState2 && switchState4 && switchState5) == HIGH) && (switchState3 == LOW)) { Serial.println("Channel 7 ON"); } else { Serial.println("Channel 7 ---"); } //Channel 8 /*VALIDATED!!!!!! */ if (((switchState1 && switchState2 && switchState5) == HIGH) && ((switchState3 or switchState4)== LOW)) { Serial.println("Channel 8 ON"); } else { Serial.println("Channel 8 ---"); } //Channel 9 /*VALIDATED!!!!!! */ if (((switchState1 && switchState2) == HIGH) && ((switchState3 or switchState4 or switchState5)== LOW)) { Serial.println("Channel 9 ON"); } else { Serial.println("Channel 9 ---"); } //Channel 10 /*VALIDATED!!!!!! */ if ((switchState1 == HIGH) && ((switchState2 or switchState3 or switchState4 or switchState5)== LOW)) { Serial.println("Channel 10 ON"); } else { Serial.println("Channel 10 ---"); } Serial.println("\n"); //Remove comment on these lines to see binary output: //Serial.print(switchState1); //Serial.print(switchState2); //Serial.print(switchState3); //Serial.println(switchState4); delay(2000); }
  21. Yes, in fact it is a multi-position rotary switch. I wish I could rewrite and implement the DCS Bios Switchmulticlass (as an additional class for this) but I do not have the know-how for this.
  22. I could not ID a part number on the switch when I looked at it and I have already enclosed it, so it would be a pain to take apart again. However, I drew a pic of it: https://i.imgur.com/7sDqMXu.png
  23. Hello! Can you help me in using a 5 bit switch for DCS Bios? I have a switch with 6 pins. Pin one is common, and the other 5 pins change. It needs at least twenty different combinations, because it is for the UHF Channel Preset switch in the A10C. I have mapped out the truth table with a multi- meter for the switch: //Comm_Pins_Channel //1_6 _1 //1_3,6_ 2 //1_ 3_3 //1_3,4_ 4 //1_3,4,6_5 //1_ 4,6_6 //1_ 4 _ 7 //1_4,5- 8 //1_ 4,5,6_9 //1_ 3,4,5,6_10 //1_ 3,4,5_11 //1_ 3,5_12 //1_3,6_13 //1_5,6 _14 //1_5 _15 //1_ 2,5_16 //1_ 2,5,6_17 //1_ 2,3,5,6_18 //1-2,3,5_19 //1_ 2,3,4,5_20 The pins on the switch I want to label as a maybe a variable bit** pin 2 = bit1 pin 3 = bit2 pin 4 = bit3 pin 5 = bit4 pin 6 = bit5 They are wired to the arduino: bit1 to A2 bit2 to A6 bit3 to A3 bit4 to A1 bit5 to A5 Common goes to ground. Any help/assistance would be greatly appreciated!!! Thanks!
×
×
  • Create New...