Jump to content

HMA's cockpit build


Hansolo

Recommended Posts

Am 1.7.2018 um 23:51 schrieb Hansolo:

DCS-BIOS AN/ARC-164 with 7-segments over RS485

 

Thanks a lot GSS Rain. I have gotten a little futher

 

 

Got the PCB's for the 7-segments of a senior member on Viperpits/Flying Falcon. Works great with these;

https://www.ebay.com/itm/1-Lot-of-25-Pieces-Avago-HDSP-U503-LED/291589746309?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2060353.m2749.l2649

 

Currently the code for the swiches of the AN/ARC-164 compares to the actual in DCS and then makes a command. I think I will start working on 'just' making them as they reacts in rest of DCS-BIOS i.e. send a command when the switch changes and be done with that. Should clear up the code somewhat.

 

The DISPLAY TEST won't work since the original ones are 16-segments. I'll see f I can dig some of those up. Code for the 7-segments are borrowed from Warhog 🙂

 

 

 /*
 The following #define tells DCS-BIOS that this is a RS-485 slave device.
 It also sets the address of this slave device. The slave address should be
 between 1 and 126 and must be unique among all devices on the same bus.
*/
#define DCSBIOS_RS485_SLAVE 27

/*
 The Arduino pin that is connected to the
 /RE and DE pins on the RS-485 transceiver.
*/
#define TXENABLE_PIN 2

#include "DcsBios.h"
#include <LedControl.h> 

LedControl lc=LedControl(30,31,32,1); //This creates an instance of a single controller named "lc"
/*
The sequence of pins used above are in the following order... LedControl(DIN,CLK,LOAD,# OF IC's) 
pin 30 is connected to the DataIn 
pin 32 is connected to the CLK 
pin 31 is connected to LOAD
the last number...(1) is for how many MAX7219 we have daisy chained.
*/
#include <timer.h>

Timer tm;

// set pin numbers:
const int Value_0 = 54;
const int Value_1 = 55;
const int Value_2 = 56;
const int Value_3 = 57;
const int Value_4 = 58;
const int Value_5 = 59;
const int Value_6 = 60;
const int Value_7 = 61;
const int Value_8 = 62;
const int Value_9 = 63;
const int Main = 44; //Function dial
const int Both = 45; //Function dial
const int Adf = 46; //Function dial
const int Squelch = 43; //Squelch

const int Selector_1 = 3; // 100Mhz
const int Selector_2 = 4; // 10Mhz
const int Selector_3 = 5; // 1MHZ
const int Selector_4 = 6; // 0.1 MHZ
const int Selector_5 = 7; // 0.25 MHZ
const int Selector_6 = 8; //Tone
const int Selector_7 = 9; //Zero
const int Selector_8 = 10; //Test
const int Selector_9 = 11; //Status
const int Selector_10 = 12; //Frequency Mode Dial MNL/PRESET/GRD

//Variables1
int DCS_Preset = 0; //Initial value set for 1
int DCS_100mhz = 0; //Initial value set for 3
int DCS_10mhz = 0; //Initial value set for 0
int DCS_1mhz = 0; //Initial value set for 0
int DCS_0_1mhz = 0; //Initial value set for 0
int DCS_0_25mhz = 0; //Initial value set for 0
int DCS_Tone = 1; // set to off
int DCS_Zero = 0; // set to off
int DCS_Test = 0; // set to off
int DCS_Status = 0; // set to off
int DCS_Mode = 0; // set to off
int DCS_Function = 0; // set to off
int DCS_Squelch = 0; // set to off

int Delay = 10; //Delay before reading

/* paste code snippets from the reference documentation here */
//UHF Prsets
void onUhfPresetSelChange(unsigned int newValue) {
   DCS_Preset = newValue;
}
DcsBios::IntegerBuffer uhfPresetSelBuffer(0x1168, 0xf800, 11, onUhfPresetSelChange);

// UHF 100mhz selector
void onUhf100mhzSelChange(unsigned int newValue) {
   DCS_100mhz = newValue;
}
DcsBios::IntegerBuffer uhf100mhzSelBuffer(0x1170, 0x0300, 8, onUhf100mhzSelChange);

// UHF 10mhz selector
void onUhf10mhzSelChange(unsigned int newValue) {
   DCS_10mhz = newValue;
}
DcsBios::IntegerBuffer uhf10mhzSelBuffer(0x1170, 0x3c00, 10, onUhf10mhzSelChange);

//uhf 1 mhz SELECTOR
void onUhf1mhzSelChange(unsigned int newValue) {
   DCS_1mhz = newValue;
}
DcsBios::IntegerBuffer uhf1mhzSelBuffer(0x1178, 0x0f00, 8, onUhf1mhzSelChange);

//UHF 0.1mhz selector
void onUhfPoint1mhzSelChange(unsigned int newValue) {
   DCS_0_1mhz = newValue;
}
DcsBios::IntegerBuffer uhfPoint1mhzSelBuffer(0x1178, 0xf000, 12, onUhfPoint1mhzSelChange);

//UHF 0.25mhz selector
void onUhfPoint25SelChange(unsigned int newValue) {
   DCS_0_25mhz = newValue;
}
DcsBios::IntegerBuffer uhfPoint25SelBuffer(0x1170, 0xc000, 14, onUhfPoint25SelChange);

//UHF L0ad
DcsBios::Switch2Pos uhfLoad("UHF_LOAD", 21);

//UHF Tone
void onUhfTToneChange(unsigned int newValue) {
   DCS_Tone = newValue;
}
DcsBios::IntegerBuffer uhfTToneBuffer(0x117c, 0x0030, 4, onUhfTToneChange);

//UHF Test
void onUhfTestChange(unsigned int newValue) {
   DCS_Test = newValue;
}
DcsBios::IntegerBuffer uhfTestBuffer(0x117c, 0x0080, 7, onUhfTestChange);

//UHF Status
void onUhfStatusChange(unsigned int newValue) {
   DCS_Status = newValue;
}
DcsBios::IntegerBuffer uhfStatusBuffer(0x117c, 0x0100, 8, onUhfStatusChange);

//UHF Mode
void onUhfModeChange(unsigned int newValue) {
   DCS_Mode = newValue;
}
DcsBios::IntegerBuffer uhfModeBuffer(0x117c, 0x0003, 0, onUhfModeChange);

//UHF Function
void onUhfFunctionChange(unsigned int newValue) {
   DCS_Function = newValue;
}
DcsBios::IntegerBuffer uhfFunctionBuffer(0x117c, 0x000c, 2, onUhfFunctionChange);

//UHF Volumen
DcsBios::Potentiometer uhfVol("UHF_VOL", A15);

//UHF Squelch
void onUhfSquelchChange(unsigned int newValue) {
   DCS_Squelch = newValue;
}
DcsBios::IntegerBuffer uhfSquelchBuffer(0x117c, 0x0040, 6, onUhfSquelchChange);

//UHF Frequency display
void onUhfFrequencyChange(char* newValue) {
  lc.setChar(0,0,newValue[0],false);
  lc.setChar(0,1,newValue[1],false);
 if ( Function_selector() == 0){
  lc.setChar(0,2,newValue[2],false); // if radio is off then don't write decimal point
 }
 else {
  lc.setChar(0,2,newValue[2],true); // if radio is ON then write decimal point 
 }
  
  lc.setChar(0,3,newValue[4],false);
  lc.setChar(0,4,newValue[5],false);
  lc.setChar(0,5,newValue[6],false);
}
DcsBios::StringBuffer<7> uhfFrequencyBuffer(0x1180, onUhfFrequencyChange);

//UHF preset display
void onUhfPresetChange(char* newValue) {
  lc.setChar(0,6,newValue[0],false);
  lc.setChar(0,7,newValue[1],false);
}
DcsBios::StringBuffer<2> uhfPresetBuffer(0x1188, onUhfPresetChange);


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,10);//set the brightness 
 lc.clearDisplay(0); //clear the display 

//The following series of "lc.setChar" commands are used to display the number 8 in each digit.  This allows us to see each that LED segment is actually working.
 lc.setChar(0,0,'8',false);// The first number...0,  means there are no other MAX7219's connected to the one we are using. 
 lc.setChar(0,1,'8',false);// The second number...1, indicates the digit you are sending data too...digit numbering starts at 0. 
 lc.setChar(0,2,'8',false);//  The third number in single quotes is the character thats displayed
 lc.setChar(0,3,'8',false);// The statement... true/false is to turn on or off the decimal point (dp) for that particular digit. 
 lc.setChar(0,4,'8',false);
 lc.setChar(0,5,'8',false);
 lc.setChar(0,6,'8',false);
 lc.setChar(0,7,'8',false);

 //Preset inputs
 DDRA = B00000000; // set PINA (digital 29-22) as inputs
 PORTA = B11111111; // Sets (digital 29-22) with internal pull up

 tm.startTimer(300, setUHF);
//Inputs
 pinMode(Value_0, INPUT_PULLUP);
 pinMode(Value_1, INPUT_PULLUP);
 pinMode(Value_2, INPUT_PULLUP);
 pinMode(Value_3, INPUT_PULLUP);
 pinMode(Value_4, INPUT_PULLUP);
 pinMode(Value_5, INPUT_PULLUP);
 pinMode(Value_6, INPUT_PULLUP);
 pinMode(Value_7, INPUT_PULLUP);
 pinMode(Value_8, INPUT_PULLUP);
 pinMode(Value_9, INPUT_PULLUP);
 pinMode(Main, INPUT_PULLUP);
 pinMode(Both, INPUT_PULLUP);
 pinMode(Adf, INPUT_PULLUP);
 pinMode(Squelch, INPUT_PULLUP);

 pinMode(Selector_1, OUTPUT);
 pinMode(Selector_2, OUTPUT);
 pinMode(Selector_3, OUTPUT);
 pinMode(Selector_4, OUTPUT);
 pinMode(Selector_5, OUTPUT);
 pinMode(Selector_6, OUTPUT);
 pinMode(Selector_7, OUTPUT);
 pinMode(Selector_8, OUTPUT);
 pinMode(Selector_9, OUTPUT);
 pinMode(Selector_10, OUTPUT);

 digitalWrite(Selector_1, HIGH);
 digitalWrite(Selector_2, HIGH);
 digitalWrite(Selector_3, HIGH);
 digitalWrite(Selector_4, HIGH);
 digitalWrite(Selector_5, HIGH);
 digitalWrite(Selector_6, HIGH);
 digitalWrite(Selector_7, HIGH);
 digitalWrite(Selector_8, HIGH);
 digitalWrite(Selector_9, HIGH);
 digitalWrite(Selector_10, HIGH);
}

int Preset() // Preset selector switch
{
 int valuePreset;
 if (PINA == B11111110) {
   valuePreset = 0;
 }
 if (PINA == B11111100) {
   valuePreset = 1;
 }
 if (PINA == B11111101) {
   valuePreset = 2;
 }
 if (PINA == B11111001) {
   valuePreset = 3;
 }
 if (PINA == B11111000) {
   valuePreset = 4;
 }
 if (PINA == B11111010) {
   valuePreset = 5;
 }
 if (PINA == B11111011) {
   valuePreset = 6;
 }
 if (PINA == B11110011) {
   valuePreset = 7;
 }
 if (PINA == B11110010) {
   valuePreset = 8;
 }
 if (PINA == B11110000) {
   valuePreset = 9;
 }
 if (PINA == B11110001) {
   valuePreset = 10;
 }
 if (PINA == B11110101) {
   valuePreset = 11;
 }
 if (PINA == B11110100) {
   valuePreset = 12;
 }
 if (PINA == B11110110) {
   valuePreset = 13;
 }
 if (PINA == B11110111) {
   valuePreset = 14;
 }
 if (PINA == B11100111) {
   valuePreset = 15;
 }
 if (PINA == B11100110) {
   valuePreset = 16;
 }
 if (PINA == B11100100) {
   valuePreset = 17;
 }
 if (PINA == B11100101) {
   valuePreset = 18;
 }
 if (PINA == B11100001) {
   valuePreset = 19;
 }
 return valuePreset;
}

int First_selector() //Check 1st selector
{
 int value_Selector_1;
 digitalWrite(Selector_1, LOW);
 delay(Delay);

 if (digitalRead(Value_1) == LOW) {
   value_Selector_1 = 0;
 }
 if (digitalRead(Value_2) == LOW) {
   value_Selector_1 = 1;
 }
 if (digitalRead(Value_3) == LOW) {
   value_Selector_1 = 2;
 }
 digitalWrite(Selector_1, HIGH);
 delay(Delay);
 return value_Selector_1;
}

int Second_selector() //Check 2nd selector
{
 int value_Selector_2;
 digitalWrite(Selector_2, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_2 = 0;
 }
 if (digitalRead(Value_1) == LOW) {
   value_Selector_2 = 1;
 }
 if (digitalRead(Value_2) == LOW) {
   value_Selector_2 = 2;
 }
 if (digitalRead(Value_3) == LOW) {
   value_Selector_2 = 3;
 }
 if (digitalRead(Value_4) == LOW) {
   value_Selector_2 = 4;
 }
 if (digitalRead(Value_5) == LOW) {
   value_Selector_2 = 5;
 }
 if (digitalRead(Value_6) == LOW) {
   value_Selector_2 = 6;
 }
 if (digitalRead(Value_7) == LOW) {
   value_Selector_2 = 7;
 }
 if (digitalRead(Value_8) == LOW) {
   value_Selector_2 = 8;
 }
 if (digitalRead(Value_9) == LOW) {
   value_Selector_2 = 9;
 }
 digitalWrite(Selector_2, HIGH);
 delay(Delay);
 return value_Selector_2;
}

int Third_selector() //Check 3rd selector
{
 int value_Selector_3;
 digitalWrite(Selector_3, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_3 = 0;
 }
 if (digitalRead(Value_1) == LOW) {
   value_Selector_3 = 1;
 }
 if (digitalRead(Value_2) == LOW) {
   value_Selector_3 = 2;
 }
 if (digitalRead(Value_3) == LOW) {
   value_Selector_3 = 3;
 }
 if (digitalRead(Value_4) == LOW) {
   value_Selector_3 = 4;
 }
 if (digitalRead(Value_5) == LOW) {
   value_Selector_3 = 5;
 }
 if (digitalRead(Value_6) == LOW) {
   value_Selector_3 = 6;
 }
 if (digitalRead(Value_7) == LOW) {
   value_Selector_3 = 7;
 }
 if (digitalRead(Value_8) == LOW) {
   value_Selector_3 = 8;
 }
 if (digitalRead(Value_9) == LOW) {
   value_Selector_3 = 9;
 }
 digitalWrite(Selector_3, HIGH);
 delay(Delay);
 return value_Selector_3;
}

int Fourth_selector() //Check 4th selector
{
 int value_Selector_4;
 digitalWrite(Selector_4, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_4 = 0;
 }
 if (digitalRead(Value_1) == LOW) {
   value_Selector_4 = 1;
 }
 if (digitalRead(Value_2) == LOW) {
   value_Selector_4 = 2;
 }
 if (digitalRead(Value_3) == LOW) {
   value_Selector_4 = 3;
 }
 if (digitalRead(Value_4) == LOW) {
   value_Selector_4 = 4;
 }
 if (digitalRead(Value_5) == LOW) {
   value_Selector_4 = 5;
 }
 if (digitalRead(Value_6) == LOW) {
   value_Selector_4 = 6;
 }
 if (digitalRead(Value_7) == LOW) {
   value_Selector_4 = 7;
 }
 if (digitalRead(Value_8) == LOW) {
   value_Selector_4 = 8;
 }
 if (digitalRead(Value_9) == LOW) {
   value_Selector_4 = 9;
 }
 digitalWrite(Selector_4, HIGH);
 delay(Delay);
 return value_Selector_4;
}

int Fifth_selector() //Check 5th selector
{
 int value_Selector_5;
 digitalWrite(Selector_5, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_5 = 0;
 }
 if (digitalRead(Value_1) == LOW) {
   value_Selector_5 = 1;
 }
 if (digitalRead(Value_2) == LOW) {
   value_Selector_5 = 2;
 }
 if (digitalRead(Value_3) == LOW) {
   value_Selector_5 = 3;
 }
 digitalWrite(Selector_5, HIGH);
 delay(Delay);
 return value_Selector_5;
}

int Sixth_selector() //Check Tone
{
 int value_Selector_6;
 digitalWrite(Selector_6, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_6 = 2;
 }
 if (digitalRead(Value_1) == LOW) {
   value_Selector_6 = 0;
 }
 if (digitalRead(Value_0) == HIGH && digitalRead(Value_1) == HIGH) {
   value_Selector_6 = 1;
 }
 digitalWrite(Selector_6, HIGH);
 delay(Delay);
 return value_Selector_6;
}

int Eight_selector() //Check Test
{
 int value_Selector_8;
 digitalWrite(Selector_8, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_8 = 1;
 }
 if (digitalRead(Value_0) == HIGH) {
   value_Selector_8 = 0;
 }
 digitalWrite(Selector_8, HIGH);
 delay(Delay);
 return value_Selector_8;
}

int Ninth_selector() //Check Status
{
 int value_Selector_9;
 digitalWrite(Selector_9, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_9 = 1;
 }
 if (digitalRead(Value_0) == HIGH) {
   value_Selector_9 = 0;
 }
 digitalWrite(Selector_9, HIGH);
 delay(Delay);
 return value_Selector_9;
}

int Tenth_selector() //Check Status
{
 int value_Selector_10;
 digitalWrite(Selector_10, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_10 = 2;
 }
 if (digitalRead(Value_1) == LOW) {
   value_Selector_10 = 1;
 }
 if (digitalRead(Value_2) == LOW) {
   value_Selector_10 = 0;
 }
 digitalWrite(Selector_10, HIGH);
 delay(Delay);
 return value_Selector_10;
}

int Function_selector() //Check Status
{
 int value_Function;

 if (digitalRead(Main) == LOW) {
   value_Function = 1;
 }
 else if (digitalRead(Both) == LOW) {
   value_Function = 2;
 }
 else if (digitalRead(Adf) == LOW) {
   value_Function = 3;
 }
 else {
   value_Function = 0;
 }
 return value_Function;
}

int Squelch_selector() //Check Status
{
 int value_Squelch;

 if (digitalRead(Squelch) == LOW) {
   value_Squelch = 0;
 }
 else {
   value_Squelch = 1;
 }
 return value_Squelch;
}


void loop() {
DcsBios::loop();
tm.runTimers();

}

void setUHF(int timer){
// Check and adjust presets
 if (DCS_Preset != Preset()) {
      if ( Preset() == 0){
   sendDcsBiosMessage("UHF_PRESET_SEL", "0");
 }
      if ( Preset() == 1){
   sendDcsBiosMessage("UHF_PRESET_SEL", "1");
 }
      if ( Preset() == 2){
   sendDcsBiosMessage("UHF_PRESET_SEL", "2");
 }
      if ( Preset() == 3){
   sendDcsBiosMessage("UHF_PRESET_SEL", "3");
 }
      if ( Preset() == 4){
   sendDcsBiosMessage("UHF_PRESET_SEL", "4");
 }
      if ( Preset() == 5){
   sendDcsBiosMessage("UHF_PRESET_SEL", "5");
 }
      if ( Preset() == 6){
   sendDcsBiosMessage("UHF_PRESET_SEL", "6");
 }
      if ( Preset() == 7){
   sendDcsBiosMessage("UHF_PRESET_SEL", "7");
 }
      if ( Preset() == 8){
   sendDcsBiosMessage("UHF_PRESET_SEL", "8");
 }
      if ( Preset() == 9){
   sendDcsBiosMessage("UHF_PRESET_SEL", "9");
 }
      if ( Preset() == 10){
   sendDcsBiosMessage("UHF_PRESET_SEL", "10");
 }
      if ( Preset() == 11){
   sendDcsBiosMessage("UHF_PRESET_SEL", "11");
 }
      if ( Preset() == 12){
   sendDcsBiosMessage("UHF_PRESET_SEL", "12");
 }
      if ( Preset() == 13){
   sendDcsBiosMessage("UHF_PRESET_SEL", "13");
 }
      if ( Preset() == 14){
   sendDcsBiosMessage("UHF_PRESET_SEL", "14");
 }
      if ( Preset() == 15){
   sendDcsBiosMessage("UHF_PRESET_SEL", "15");
 }
      if ( Preset() == 16){
   sendDcsBiosMessage("UHF_PRESET_SEL", "16");
 }
      if ( Preset() == 17){
   sendDcsBiosMessage("UHF_PRESET_SEL", "17");
 }
      if ( Preset() == 18){
   sendDcsBiosMessage("UHF_PRESET_SEL", "18");
 }
      if ( Preset() == 19){
   sendDcsBiosMessage("UHF_PRESET_SEL", "19");
 }
}

// Check and adjust 1st selector
   if (DCS_100mhz != First_selector()) {
    if ( First_selector() == 0){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "0");
 }
    if ( First_selector() == 1){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "1");
 }
    if ( First_selector() == 2){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "2");
 }
    if ( First_selector() == 3){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "3");
 }
    if ( First_selector() == 4){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "4");
 }
    if ( First_selector() == 5){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "5");
 }
    if ( First_selector() == 6){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "6");
 }
    if ( First_selector() == 7){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "7");
 }
    if ( First_selector() == 8){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "8");
 }
    if ( First_selector() == 9){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "9");
 }
}
// Check and adjust 2nd selector
   if (DCS_10mhz != Second_selector()) {
    if ( Second_selector() == 0){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "0");
 }
    if ( Second_selector() == 1){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "1");
 }
    if ( Second_selector() == 2){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "2");
 }
    if ( Second_selector() == 3){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "3");
 }
    if ( Second_selector() == 4){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "4");
 }
    if ( Second_selector() == 5){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "5");
 }
    if ( Second_selector() == 6){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "6");
 }
    if ( Second_selector() == 7){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "7");
 }
    if ( Second_selector() == 8){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "8");
 }
    if ( Second_selector() == 9){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "9");
 }
}

// Check and adjust 3rd selector
   if (DCS_1mhz != Third_selector()) {
    if ( Third_selector() == 0){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "0");
 }
    if ( Third_selector() == 1){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "1");
 }
    if ( Third_selector() == 2){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "2");
 }
    if ( Third_selector() == 3){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "3");
 }
    if ( Third_selector() == 4){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "4");
 }
    if ( Third_selector() == 5){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "5");
 }
    if ( Third_selector() == 6){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "6");
 }
    if ( Third_selector() == 7){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "7");
 }
    if ( Third_selector() == 8){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "8");
 }
    if ( Third_selector() == 9){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "9");
 }
}


// Check and adjust 4th selector
   if (DCS_0_1mhz != Fourth_selector()) {
    if ( Fourth_selector() == 0){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "0");
 }
    if ( Fourth_selector() == 1){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "1");
 }
    if ( Fourth_selector() == 2){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "2");
 }
    if ( Fourth_selector() == 3){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "3");
 }
    if ( Fourth_selector() == 4){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "4");
 }
    if ( Fourth_selector() == 5){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "5");
 }
    if ( Fourth_selector() == 6){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "6");
 }
    if ( Fourth_selector() == 7){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "7");
 }
    if ( Fourth_selector() == 8){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "8");
 }
    if ( Fourth_selector() == 9){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "9");
 }
}

// Check and adjust 5th selector
 if (DCS_0_25mhz != Fifth_selector()) {
   if ( Fifth_selector() == 0){
      sendDcsBiosMessage("UHF_POINT25_SEL", "0");
 }
  if ( Fifth_selector() == 1){
      sendDcsBiosMessage("UHF_POINT25_SEL", "1");
 }
   if ( Fifth_selector() == 2){
      sendDcsBiosMessage("UHF_POINT25_SEL", "2");
 }
   if ( Fifth_selector() == 3){
      sendDcsBiosMessage("UHF_POINT25_SEL", "3");
 }
}

// Check and adjust Tone
 if (DCS_Tone != Sixth_selector()) {
   if ( Sixth_selector() == 0){
      sendDcsBiosMessage("UHF_T_TONE", "0");
 }
  if ( Sixth_selector() == 1){
      sendDcsBiosMessage("UHF_T_TONE", "1");
 }
   if ( Sixth_selector() == 2){
      sendDcsBiosMessage("UHF_T_TONE", "2");
 }
}

// Check and adjust Test
 if (DCS_Test != Eight_selector()) {
   if ( Eight_selector() == 0){
      sendDcsBiosMessage("UHF_TEST", "0");
 }
  if ( Eight_selector() == 1){
      sendDcsBiosMessage("UHF_TEST", "1");
 }
}

// Check and adjust Status
 if (DCS_Status != Ninth_selector()) {
   if ( Ninth_selector() == 0){
      sendDcsBiosMessage("UHF_STATUS", "0");
 }
  if ( Ninth_selector() == 1){
      sendDcsBiosMessage("UHF_STATUS", "1");
 }
}

// Check and adjust Mode
if (DCS_Mode != Tenth_selector()) {
   if ( Tenth_selector() == 0){
      sendDcsBiosMessage("UHF_MODE", "0");
 }
  if ( Tenth_selector() == 1){
      sendDcsBiosMessage("UHF_MODE", "1");
 }
  if ( Tenth_selector() == 2){
      sendDcsBiosMessage("UHF_MODE", "2");
 }
}

// Check and adjust Function
if (DCS_Function != Function_selector()) {
   if ( Function_selector() == 0){
      sendDcsBiosMessage("UHF_FUNCTION", "0");
 }
  if ( Function_selector() == 1){
      sendDcsBiosMessage("UHF_FUNCTION", "1");
 }
  if ( Function_selector() == 2){
      sendDcsBiosMessage("UHF_FUNCTION", "2");
 }
  if ( Function_selector() == 3){
      sendDcsBiosMessage("UHF_FUNCTION", "3");
 }
}

// Check and adjust Squelch
if (DCS_Squelch != Squelch_selector()) {
   if ( Squelch_selector() == 0){
      sendDcsBiosMessage("UHF_SQUELCH", "0");
 }
  if ( Squelch_selector() == 1){
      sendDcsBiosMessage("UHF_SQUELCH", "1");
 }
}

}

 

 

 

Cheers

Hans

 

 

Am 1.7.2018 um 23:51 schrieb Hansolo:

DCS-BIOS AN/ARC-164 with 7-segments over RS485

 

Thanks a lot GSS Rain. I have gotten a little futher

 

 

Got the PCB's for the 7-segments of a senior member on Viperpits/Flying Falcon. Works great with these;

https://www.ebay.com/itm/1-Lot-of-25-Pieces-Avago-HDSP-U503-LED/291589746309?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2060353.m2749.l2649

 

Currently the code for the swiches of the AN/ARC-164 compares to the actual in DCS and then makes a command. I think I will start working on 'just' making them as they reacts in rest of DCS-BIOS i.e. send a command when the switch changes and be done with that. Should clear up the code somewhat.

 

The DISPLAY TEST won't work since the original ones are 16-segments. I'll see f I can dig some of those up. Code for the 7-segments are borrowed from Warhog 🙂

 

 

 /*
 The following #define tells DCS-BIOS that this is a RS-485 slave device.
 It also sets the address of this slave device. The slave address should be
 between 1 and 126 and must be unique among all devices on the same bus.
*/
#define DCSBIOS_RS485_SLAVE 27

/*
 The Arduino pin that is connected to the
 /RE and DE pins on the RS-485 transceiver.
*/
#define TXENABLE_PIN 2

#include "DcsBios.h"
#include <LedControl.h> 

LedControl lc=LedControl(30,31,32,1); //This creates an instance of a single controller named "lc"
/*
The sequence of pins used above are in the following order... LedControl(DIN,CLK,LOAD,# OF IC's) 
pin 30 is connected to the DataIn 
pin 32 is connected to the CLK 
pin 31 is connected to LOAD
the last number...(1) is for how many MAX7219 we have daisy chained.
*/
#include <timer.h>

Timer tm;

// set pin numbers:
const int Value_0 = 54;
const int Value_1 = 55;
const int Value_2 = 56;
const int Value_3 = 57;
const int Value_4 = 58;
const int Value_5 = 59;
const int Value_6 = 60;
const int Value_7 = 61;
const int Value_8 = 62;
const int Value_9 = 63;
const int Main = 44; //Function dial
const int Both = 45; //Function dial
const int Adf = 46; //Function dial
const int Squelch = 43; //Squelch

const int Selector_1 = 3; // 100Mhz
const int Selector_2 = 4; // 10Mhz
const int Selector_3 = 5; // 1MHZ
const int Selector_4 = 6; // 0.1 MHZ
const int Selector_5 = 7; // 0.25 MHZ
const int Selector_6 = 8; //Tone
const int Selector_7 = 9; //Zero
const int Selector_8 = 10; //Test
const int Selector_9 = 11; //Status
const int Selector_10 = 12; //Frequency Mode Dial MNL/PRESET/GRD

//Variables1
int DCS_Preset = 0; //Initial value set for 1
int DCS_100mhz = 0; //Initial value set for 3
int DCS_10mhz = 0; //Initial value set for 0
int DCS_1mhz = 0; //Initial value set for 0
int DCS_0_1mhz = 0; //Initial value set for 0
int DCS_0_25mhz = 0; //Initial value set for 0
int DCS_Tone = 1; // set to off
int DCS_Zero = 0; // set to off
int DCS_Test = 0; // set to off
int DCS_Status = 0; // set to off
int DCS_Mode = 0; // set to off
int DCS_Function = 0; // set to off
int DCS_Squelch = 0; // set to off

int Delay = 10; //Delay before reading

/* paste code snippets from the reference documentation here */
//UHF Prsets
void onUhfPresetSelChange(unsigned int newValue) {
   DCS_Preset = newValue;
}
DcsBios::IntegerBuffer uhfPresetSelBuffer(0x1168, 0xf800, 11, onUhfPresetSelChange);

// UHF 100mhz selector
void onUhf100mhzSelChange(unsigned int newValue) {
   DCS_100mhz = newValue;
}
DcsBios::IntegerBuffer uhf100mhzSelBuffer(0x1170, 0x0300, 8, onUhf100mhzSelChange);

// UHF 10mhz selector
void onUhf10mhzSelChange(unsigned int newValue) {
   DCS_10mhz = newValue;
}
DcsBios::IntegerBuffer uhf10mhzSelBuffer(0x1170, 0x3c00, 10, onUhf10mhzSelChange);

//uhf 1 mhz SELECTOR
void onUhf1mhzSelChange(unsigned int newValue) {
   DCS_1mhz = newValue;
}
DcsBios::IntegerBuffer uhf1mhzSelBuffer(0x1178, 0x0f00, 8, onUhf1mhzSelChange);

//UHF 0.1mhz selector
void onUhfPoint1mhzSelChange(unsigned int newValue) {
   DCS_0_1mhz = newValue;
}
DcsBios::IntegerBuffer uhfPoint1mhzSelBuffer(0x1178, 0xf000, 12, onUhfPoint1mhzSelChange);

//UHF 0.25mhz selector
void onUhfPoint25SelChange(unsigned int newValue) {
   DCS_0_25mhz = newValue;
}
DcsBios::IntegerBuffer uhfPoint25SelBuffer(0x1170, 0xc000, 14, onUhfPoint25SelChange);

//UHF L0ad
DcsBios::Switch2Pos uhfLoad("UHF_LOAD", 21);

//UHF Tone
void onUhfTToneChange(unsigned int newValue) {
   DCS_Tone = newValue;
}
DcsBios::IntegerBuffer uhfTToneBuffer(0x117c, 0x0030, 4, onUhfTToneChange);

//UHF Test
void onUhfTestChange(unsigned int newValue) {
   DCS_Test = newValue;
}
DcsBios::IntegerBuffer uhfTestBuffer(0x117c, 0x0080, 7, onUhfTestChange);

//UHF Status
void onUhfStatusChange(unsigned int newValue) {
   DCS_Status = newValue;
}
DcsBios::IntegerBuffer uhfStatusBuffer(0x117c, 0x0100, 8, onUhfStatusChange);

//UHF Mode
void onUhfModeChange(unsigned int newValue) {
   DCS_Mode = newValue;
}
DcsBios::IntegerBuffer uhfModeBuffer(0x117c, 0x0003, 0, onUhfModeChange);

//UHF Function
void onUhfFunctionChange(unsigned int newValue) {
   DCS_Function = newValue;
}
DcsBios::IntegerBuffer uhfFunctionBuffer(0x117c, 0x000c, 2, onUhfFunctionChange);

//UHF Volumen
DcsBios::Potentiometer uhfVol("UHF_VOL", A15);

//UHF Squelch
void onUhfSquelchChange(unsigned int newValue) {
   DCS_Squelch = newValue;
}
DcsBios::IntegerBuffer uhfSquelchBuffer(0x117c, 0x0040, 6, onUhfSquelchChange);

//UHF Frequency display
void onUhfFrequencyChange(char* newValue) {
  lc.setChar(0,0,newValue[0],false);
  lc.setChar(0,1,newValue[1],false);
 if ( Function_selector() == 0){
  lc.setChar(0,2,newValue[2],false); // if radio is off then don't write decimal point
 }
 else {
  lc.setChar(0,2,newValue[2],true); // if radio is ON then write decimal point 
 }
  
  lc.setChar(0,3,newValue[4],false);
  lc.setChar(0,4,newValue[5],false);
  lc.setChar(0,5,newValue[6],false);
}
DcsBios::StringBuffer<7> uhfFrequencyBuffer(0x1180, onUhfFrequencyChange);

//UHF preset display
void onUhfPresetChange(char* newValue) {
  lc.setChar(0,6,newValue[0],false);
  lc.setChar(0,7,newValue[1],false);
}
DcsBios::StringBuffer<2> uhfPresetBuffer(0x1188, onUhfPresetChange);


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,10);//set the brightness 
 lc.clearDisplay(0); //clear the display 

//The following series of "lc.setChar" commands are used to display the number 8 in each digit.  This allows us to see each that LED segment is actually working.
 lc.setChar(0,0,'8',false);// The first number...0,  means there are no other MAX7219's connected to the one we are using. 
 lc.setChar(0,1,'8',false);// The second number...1, indicates the digit you are sending data too...digit numbering starts at 0. 
 lc.setChar(0,2,'8',false);//  The third number in single quotes is the character thats displayed
 lc.setChar(0,3,'8',false);// The statement... true/false is to turn on or off the decimal point (dp) for that particular digit. 
 lc.setChar(0,4,'8',false);
 lc.setChar(0,5,'8',false);
 lc.setChar(0,6,'8',false);
 lc.setChar(0,7,'8',false);

 //Preset inputs
 DDRA = B00000000; // set PINA (digital 29-22) as inputs
 PORTA = B11111111; // Sets (digital 29-22) with internal pull up

 tm.startTimer(300, setUHF);
//Inputs
 pinMode(Value_0, INPUT_PULLUP);
 pinMode(Value_1, INPUT_PULLUP);
 pinMode(Value_2, INPUT_PULLUP);
 pinMode(Value_3, INPUT_PULLUP);
 pinMode(Value_4, INPUT_PULLUP);
 pinMode(Value_5, INPUT_PULLUP);
 pinMode(Value_6, INPUT_PULLUP);
 pinMode(Value_7, INPUT_PULLUP);
 pinMode(Value_8, INPUT_PULLUP);
 pinMode(Value_9, INPUT_PULLUP);
 pinMode(Main, INPUT_PULLUP);
 pinMode(Both, INPUT_PULLUP);
 pinMode(Adf, INPUT_PULLUP);
 pinMode(Squelch, INPUT_PULLUP);

 pinMode(Selector_1, OUTPUT);
 pinMode(Selector_2, OUTPUT);
 pinMode(Selector_3, OUTPUT);
 pinMode(Selector_4, OUTPUT);
 pinMode(Selector_5, OUTPUT);
 pinMode(Selector_6, OUTPUT);
 pinMode(Selector_7, OUTPUT);
 pinMode(Selector_8, OUTPUT);
 pinMode(Selector_9, OUTPUT);
 pinMode(Selector_10, OUTPUT);

 digitalWrite(Selector_1, HIGH);
 digitalWrite(Selector_2, HIGH);
 digitalWrite(Selector_3, HIGH);
 digitalWrite(Selector_4, HIGH);
 digitalWrite(Selector_5, HIGH);
 digitalWrite(Selector_6, HIGH);
 digitalWrite(Selector_7, HIGH);
 digitalWrite(Selector_8, HIGH);
 digitalWrite(Selector_9, HIGH);
 digitalWrite(Selector_10, HIGH);
}

int Preset() // Preset selector switch
{
 int valuePreset;
 if (PINA == B11111110) {
   valuePreset = 0;
 }
 if (PINA == B11111100) {
   valuePreset = 1;
 }
 if (PINA == B11111101) {
   valuePreset = 2;
 }
 if (PINA == B11111001) {
   valuePreset = 3;
 }
 if (PINA == B11111000) {
   valuePreset = 4;
 }
 if (PINA == B11111010) {
   valuePreset = 5;
 }
 if (PINA == B11111011) {
   valuePreset = 6;
 }
 if (PINA == B11110011) {
   valuePreset = 7;
 }
 if (PINA == B11110010) {
   valuePreset = 8;
 }
 if (PINA == B11110000) {
   valuePreset = 9;
 }
 if (PINA == B11110001) {
   valuePreset = 10;
 }
 if (PINA == B11110101) {
   valuePreset = 11;
 }
 if (PINA == B11110100) {
   valuePreset = 12;
 }
 if (PINA == B11110110) {
   valuePreset = 13;
 }
 if (PINA == B11110111) {
   valuePreset = 14;
 }
 if (PINA == B11100111) {
   valuePreset = 15;
 }
 if (PINA == B11100110) {
   valuePreset = 16;
 }
 if (PINA == B11100100) {
   valuePreset = 17;
 }
 if (PINA == B11100101) {
   valuePreset = 18;
 }
 if (PINA == B11100001) {
   valuePreset = 19;
 }
 return valuePreset;
}

int First_selector() //Check 1st selector
{
 int value_Selector_1;
 digitalWrite(Selector_1, LOW);
 delay(Delay);

 if (digitalRead(Value_1) == LOW) {
   value_Selector_1 = 0;
 }
 if (digitalRead(Value_2) == LOW) {
   value_Selector_1 = 1;
 }
 if (digitalRead(Value_3) == LOW) {
   value_Selector_1 = 2;
 }
 digitalWrite(Selector_1, HIGH);
 delay(Delay);
 return value_Selector_1;
}

int Second_selector() //Check 2nd selector
{
 int value_Selector_2;
 digitalWrite(Selector_2, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_2 = 0;
 }
 if (digitalRead(Value_1) == LOW) {
   value_Selector_2 = 1;
 }
 if (digitalRead(Value_2) == LOW) {
   value_Selector_2 = 2;
 }
 if (digitalRead(Value_3) == LOW) {
   value_Selector_2 = 3;
 }
 if (digitalRead(Value_4) == LOW) {
   value_Selector_2 = 4;
 }
 if (digitalRead(Value_5) == LOW) {
   value_Selector_2 = 5;
 }
 if (digitalRead(Value_6) == LOW) {
   value_Selector_2 = 6;
 }
 if (digitalRead(Value_7) == LOW) {
   value_Selector_2 = 7;
 }
 if (digitalRead(Value_8) == LOW) {
   value_Selector_2 = 8;
 }
 if (digitalRead(Value_9) == LOW) {
   value_Selector_2 = 9;
 }
 digitalWrite(Selector_2, HIGH);
 delay(Delay);
 return value_Selector_2;
}

int Third_selector() //Check 3rd selector
{
 int value_Selector_3;
 digitalWrite(Selector_3, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_3 = 0;
 }
 if (digitalRead(Value_1) == LOW) {
   value_Selector_3 = 1;
 }
 if (digitalRead(Value_2) == LOW) {
   value_Selector_3 = 2;
 }
 if (digitalRead(Value_3) == LOW) {
   value_Selector_3 = 3;
 }
 if (digitalRead(Value_4) == LOW) {
   value_Selector_3 = 4;
 }
 if (digitalRead(Value_5) == LOW) {
   value_Selector_3 = 5;
 }
 if (digitalRead(Value_6) == LOW) {
   value_Selector_3 = 6;
 }
 if (digitalRead(Value_7) == LOW) {
   value_Selector_3 = 7;
 }
 if (digitalRead(Value_8) == LOW) {
   value_Selector_3 = 8;
 }
 if (digitalRead(Value_9) == LOW) {
   value_Selector_3 = 9;
 }
 digitalWrite(Selector_3, HIGH);
 delay(Delay);
 return value_Selector_3;
}

int Fourth_selector() //Check 4th selector
{
 int value_Selector_4;
 digitalWrite(Selector_4, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_4 = 0;
 }
 if (digitalRead(Value_1) == LOW) {
   value_Selector_4 = 1;
 }
 if (digitalRead(Value_2) == LOW) {
   value_Selector_4 = 2;
 }
 if (digitalRead(Value_3) == LOW) {
   value_Selector_4 = 3;
 }
 if (digitalRead(Value_4) == LOW) {
   value_Selector_4 = 4;
 }
 if (digitalRead(Value_5) == LOW) {
   value_Selector_4 = 5;
 }
 if (digitalRead(Value_6) == LOW) {
   value_Selector_4 = 6;
 }
 if (digitalRead(Value_7) == LOW) {
   value_Selector_4 = 7;
 }
 if (digitalRead(Value_8) == LOW) {
   value_Selector_4 = 8;
 }
 if (digitalRead(Value_9) == LOW) {
   value_Selector_4 = 9;
 }
 digitalWrite(Selector_4, HIGH);
 delay(Delay);
 return value_Selector_4;
}

int Fifth_selector() //Check 5th selector
{
 int value_Selector_5;
 digitalWrite(Selector_5, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_5 = 0;
 }
 if (digitalRead(Value_1) == LOW) {
   value_Selector_5 = 1;
 }
 if (digitalRead(Value_2) == LOW) {
   value_Selector_5 = 2;
 }
 if (digitalRead(Value_3) == LOW) {
   value_Selector_5 = 3;
 }
 digitalWrite(Selector_5, HIGH);
 delay(Delay);
 return value_Selector_5;
}

int Sixth_selector() //Check Tone
{
 int value_Selector_6;
 digitalWrite(Selector_6, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_6 = 2;
 }
 if (digitalRead(Value_1) == LOW) {
   value_Selector_6 = 0;
 }
 if (digitalRead(Value_0) == HIGH && digitalRead(Value_1) == HIGH) {
   value_Selector_6 = 1;
 }
 digitalWrite(Selector_6, HIGH);
 delay(Delay);
 return value_Selector_6;
}

int Eight_selector() //Check Test
{
 int value_Selector_8;
 digitalWrite(Selector_8, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_8 = 1;
 }
 if (digitalRead(Value_0) == HIGH) {
   value_Selector_8 = 0;
 }
 digitalWrite(Selector_8, HIGH);
 delay(Delay);
 return value_Selector_8;
}

int Ninth_selector() //Check Status
{
 int value_Selector_9;
 digitalWrite(Selector_9, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_9 = 1;
 }
 if (digitalRead(Value_0) == HIGH) {
   value_Selector_9 = 0;
 }
 digitalWrite(Selector_9, HIGH);
 delay(Delay);
 return value_Selector_9;
}

int Tenth_selector() //Check Status
{
 int value_Selector_10;
 digitalWrite(Selector_10, LOW);
 delay(Delay);

 if (digitalRead(Value_0) == LOW) {
   value_Selector_10 = 2;
 }
 if (digitalRead(Value_1) == LOW) {
   value_Selector_10 = 1;
 }
 if (digitalRead(Value_2) == LOW) {
   value_Selector_10 = 0;
 }
 digitalWrite(Selector_10, HIGH);
 delay(Delay);
 return value_Selector_10;
}

int Function_selector() //Check Status
{
 int value_Function;

 if (digitalRead(Main) == LOW) {
   value_Function = 1;
 }
 else if (digitalRead(Both) == LOW) {
   value_Function = 2;
 }
 else if (digitalRead(Adf) == LOW) {
   value_Function = 3;
 }
 else {
   value_Function = 0;
 }
 return value_Function;
}

int Squelch_selector() //Check Status
{
 int value_Squelch;

 if (digitalRead(Squelch) == LOW) {
   value_Squelch = 0;
 }
 else {
   value_Squelch = 1;
 }
 return value_Squelch;
}


void loop() {
DcsBios::loop();
tm.runTimers();

}

void setUHF(int timer){
// Check and adjust presets
 if (DCS_Preset != Preset()) {
      if ( Preset() == 0){
   sendDcsBiosMessage("UHF_PRESET_SEL", "0");
 }
      if ( Preset() == 1){
   sendDcsBiosMessage("UHF_PRESET_SEL", "1");
 }
      if ( Preset() == 2){
   sendDcsBiosMessage("UHF_PRESET_SEL", "2");
 }
      if ( Preset() == 3){
   sendDcsBiosMessage("UHF_PRESET_SEL", "3");
 }
      if ( Preset() == 4){
   sendDcsBiosMessage("UHF_PRESET_SEL", "4");
 }
      if ( Preset() == 5){
   sendDcsBiosMessage("UHF_PRESET_SEL", "5");
 }
      if ( Preset() == 6){
   sendDcsBiosMessage("UHF_PRESET_SEL", "6");
 }
      if ( Preset() == 7){
   sendDcsBiosMessage("UHF_PRESET_SEL", "7");
 }
      if ( Preset() == 8){
   sendDcsBiosMessage("UHF_PRESET_SEL", "8");
 }
      if ( Preset() == 9){
   sendDcsBiosMessage("UHF_PRESET_SEL", "9");
 }
      if ( Preset() == 10){
   sendDcsBiosMessage("UHF_PRESET_SEL", "10");
 }
      if ( Preset() == 11){
   sendDcsBiosMessage("UHF_PRESET_SEL", "11");
 }
      if ( Preset() == 12){
   sendDcsBiosMessage("UHF_PRESET_SEL", "12");
 }
      if ( Preset() == 13){
   sendDcsBiosMessage("UHF_PRESET_SEL", "13");
 }
      if ( Preset() == 14){
   sendDcsBiosMessage("UHF_PRESET_SEL", "14");
 }
      if ( Preset() == 15){
   sendDcsBiosMessage("UHF_PRESET_SEL", "15");
 }
      if ( Preset() == 16){
   sendDcsBiosMessage("UHF_PRESET_SEL", "16");
 }
      if ( Preset() == 17){
   sendDcsBiosMessage("UHF_PRESET_SEL", "17");
 }
      if ( Preset() == 18){
   sendDcsBiosMessage("UHF_PRESET_SEL", "18");
 }
      if ( Preset() == 19){
   sendDcsBiosMessage("UHF_PRESET_SEL", "19");
 }
}

// Check and adjust 1st selector
   if (DCS_100mhz != First_selector()) {
    if ( First_selector() == 0){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "0");
 }
    if ( First_selector() == 1){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "1");
 }
    if ( First_selector() == 2){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "2");
 }
    if ( First_selector() == 3){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "3");
 }
    if ( First_selector() == 4){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "4");
 }
    if ( First_selector() == 5){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "5");
 }
    if ( First_selector() == 6){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "6");
 }
    if ( First_selector() == 7){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "7");
 }
    if ( First_selector() == 8){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "8");
 }
    if ( First_selector() == 9){
   sendDcsBiosMessage("UHF_100MHZ_SEL", "9");
 }
}
// Check and adjust 2nd selector
   if (DCS_10mhz != Second_selector()) {
    if ( Second_selector() == 0){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "0");
 }
    if ( Second_selector() == 1){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "1");
 }
    if ( Second_selector() == 2){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "2");
 }
    if ( Second_selector() == 3){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "3");
 }
    if ( Second_selector() == 4){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "4");
 }
    if ( Second_selector() == 5){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "5");
 }
    if ( Second_selector() == 6){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "6");
 }
    if ( Second_selector() == 7){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "7");
 }
    if ( Second_selector() == 8){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "8");
 }
    if ( Second_selector() == 9){
   sendDcsBiosMessage("UHF_10MHZ_SEL", "9");
 }
}

// Check and adjust 3rd selector
   if (DCS_1mhz != Third_selector()) {
    if ( Third_selector() == 0){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "0");
 }
    if ( Third_selector() == 1){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "1");
 }
    if ( Third_selector() == 2){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "2");
 }
    if ( Third_selector() == 3){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "3");
 }
    if ( Third_selector() == 4){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "4");
 }
    if ( Third_selector() == 5){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "5");
 }
    if ( Third_selector() == 6){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "6");
 }
    if ( Third_selector() == 7){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "7");
 }
    if ( Third_selector() == 8){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "8");
 }
    if ( Third_selector() == 9){
   sendDcsBiosMessage("UHF_1MHZ_SEL", "9");
 }
}


// Check and adjust 4th selector
   if (DCS_0_1mhz != Fourth_selector()) {
    if ( Fourth_selector() == 0){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "0");
 }
    if ( Fourth_selector() == 1){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "1");
 }
    if ( Fourth_selector() == 2){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "2");
 }
    if ( Fourth_selector() == 3){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "3");
 }
    if ( Fourth_selector() == 4){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "4");
 }
    if ( Fourth_selector() == 5){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "5");
 }
    if ( Fourth_selector() == 6){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "6");
 }
    if ( Fourth_selector() == 7){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "7");
 }
    if ( Fourth_selector() == 8){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "8");
 }
    if ( Fourth_selector() == 9){
   sendDcsBiosMessage("UHF_POINT1MHZ_SEL", "9");
 }
}

// Check and adjust 5th selector
 if (DCS_0_25mhz != Fifth_selector()) {
   if ( Fifth_selector() == 0){
      sendDcsBiosMessage("UHF_POINT25_SEL", "0");
 }
  if ( Fifth_selector() == 1){
      sendDcsBiosMessage("UHF_POINT25_SEL", "1");
 }
   if ( Fifth_selector() == 2){
      sendDcsBiosMessage("UHF_POINT25_SEL", "2");
 }
   if ( Fifth_selector() == 3){
      sendDcsBiosMessage("UHF_POINT25_SEL", "3");
 }
}

// Check and adjust Tone
 if (DCS_Tone != Sixth_selector()) {
   if ( Sixth_selector() == 0){
      sendDcsBiosMessage("UHF_T_TONE", "0");
 }
  if ( Sixth_selector() == 1){
      sendDcsBiosMessage("UHF_T_TONE", "1");
 }
   if ( Sixth_selector() == 2){
      sendDcsBiosMessage("UHF_T_TONE", "2");
 }
}

// Check and adjust Test
 if (DCS_Test != Eight_selector()) {
   if ( Eight_selector() == 0){
      sendDcsBiosMessage("UHF_TEST", "0");
 }
  if ( Eight_selector() == 1){
      sendDcsBiosMessage("UHF_TEST", "1");
 }
}

// Check and adjust Status
 if (DCS_Status != Ninth_selector()) {
   if ( Ninth_selector() == 0){
      sendDcsBiosMessage("UHF_STATUS", "0");
 }
  if ( Ninth_selector() == 1){
      sendDcsBiosMessage("UHF_STATUS", "1");
 }
}

// Check and adjust Mode
if (DCS_Mode != Tenth_selector()) {
   if ( Tenth_selector() == 0){
      sendDcsBiosMessage("UHF_MODE", "0");
 }
  if ( Tenth_selector() == 1){
      sendDcsBiosMessage("UHF_MODE", "1");
 }
  if ( Tenth_selector() == 2){
      sendDcsBiosMessage("UHF_MODE", "2");
 }
}

// Check and adjust Function
if (DCS_Function != Function_selector()) {
   if ( Function_selector() == 0){
      sendDcsBiosMessage("UHF_FUNCTION", "0");
 }
  if ( Function_selector() == 1){
      sendDcsBiosMessage("UHF_FUNCTION", "1");
 }
  if ( Function_selector() == 2){
      sendDcsBiosMessage("UHF_FUNCTION", "2");
 }
  if ( Function_selector() == 3){
      sendDcsBiosMessage("UHF_FUNCTION", "3");
 }
}

// Check and adjust Squelch
if (DCS_Squelch != Squelch_selector()) {
   if ( Squelch_selector() == 0){
      sendDcsBiosMessage("UHF_SQUELCH", "0");
 }
  if ( Squelch_selector() == 1){
      sendDcsBiosMessage("UHF_SQUELCH", "1");
 }
}

}

 

 

 

Cheers

Hans

 

Hi Hans,

 

what Timer-Library did you use?

 

 

Cheers

Markus

Link to comment
Share on other sites

  • 5 months later...

G'day blokes and blokettes,

 

Awesome thread here really love seeing everyone's success.

 

Han, or anyone able to explain why this code below would not communicate with DCS at all? I am using a MEGA2560 board. My matrix is wired like the screenshot attached, the only difference being which pins the rows and columns are connected to (they are wired as per the code below).

I tried wiring buttons individually to pins through a diode (1N4001) with the cathode pointing to the rows, and that didn't work either when I used the generic Control Reference codes in the #define DCSBIOS_DEFAULT_SERIAL. Both methods don't work with IRQ_SERIAL either.

When I say it doesn't work, I mean I get zero response, not even ghosting etc. DCS BIOS is configured correctly, I get virtual cockpit connection and COMM connection through the correct port etc. and the code verifies and successfully uploads to the board.

This is for an F18 UFC using the control reference for the 'CASE' SendDcsBiosMessage lines.

 

Cheers in advance.

 

#define DCSBIOS_DEFAULT_SERIAL
 
#include <Keypad.h>
#include <DcsBios.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
    {'1','2','3','B'},
    {'4','5','6','C'},
    {'7','8','9','D'},
    {'*','0','#','E'} //ufc keypad minus the top right option select (A) as it didn't neatly fit my matrix
};

byte rowPins[ROWS] = {8,9,10,11}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4,5,6,7}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


void setup(){
    DcsBios::setup();
    Serial.begin(9600);
    keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
}

void loop(){
  DcsBios::loop();
    char key = keypad.getKey();
}

void keypadEvent(KeypadEvent KEY){
  switch (keypad.getState()) { // gives PRESSED, HOLD or RELEASED
    case PRESSED: 
    switch(KEY){
      case '1': sendDcsBiosMessage("UFC_1", "1"); break;
      case '2': sendDcsBiosMessage("UFC_2", "1"); break;
      case '3': sendDcsBiosMessage("UFC_3", "1"); break;
      case '4': sendDcsBiosMessage("UFC_4", "1"); break;
      case '5': sendDcsBiosMessage("UFC_5", "1"); break;
      case '6': sendDcsBiosMessage("UFC_6", "1"); break;
      case '7': sendDcsBiosMessage("UFC_7", "1"); break;
      case '8': sendDcsBiosMessage("UFC_8", "1"); break;
      case '9': sendDcsBiosMessage("UFC_9", "1"); break;
      case '0': sendDcsBiosMessage("UFC_0", "1"); break;

      case '*': sendDcsBiosMessage("UFC_CLR", "1"); break;
      case '#': sendDcsBiosMessage("UFC_ENT", "1"); break;
      
      case 'B': sendDcsBiosMessage("UFC_OS2", "1"); break;
      case 'C': sendDcsBiosMessage("UFC_OS3", "1"); break;
      case 'D': sendDcsBiosMessage("UFC_OS4", "1"); break;
      case 'E': sendDcsBiosMessage("UFC_OS5", "1"); break;
      
    }}

     switch (keypad.getState()) { // gives PRESSED, HOLD or RELEASED
    case RELEASED: 
    switch(KEY){
      case '1': sendDcsBiosMessage("UFC_1", "0"); break;
      case '2': sendDcsBiosMessage("UFC_2", "0"); break;
      case '3': sendDcsBiosMessage("UFC_3", "0"); break;
      case '4': sendDcsBiosMessage("UFC_4", "0"); break;
      case '5': sendDcsBiosMessage("UFC_5", "0"); break;
      case '6': sendDcsBiosMessage("UFC_6", "0"); break;
      case '7': sendDcsBiosMessage("UFC_7", "0"); break;
      case '8': sendDcsBiosMessage("UFC_8", "0"); break;
      case '9': sendDcsBiosMessage("UFC_9", "0"); break;
      case '0': sendDcsBiosMessage("UFC_0", "0"); break;

      case '*': sendDcsBiosMessage("UFC_CLR", "0"); break;
      case '#': sendDcsBiosMessage("UFC_ENT", "0"); break;
      
      case 'B': sendDcsBiosMessage("UFC_OS2", "0"); break;
      case 'C': sendDcsBiosMessage("UFC_OS3", "0"); break;
      case 'D': sendDcsBiosMessage("UFC_OS4", "0"); break;
      case 'E': sendDcsBiosMessage("UFC_OS5", "0"); break;

    }}
}

Button Matrix Wiring.JPG

Link to comment
Share on other sites

15 hours ago, RassieRaider said:

G'day blokes and blokettes,

 

Awesome thread here really love seeing everyone's success.

 

Han, or anyone able to explain why this code below would not communicate with DCS at all? I am using a MEGA2560 board. My matrix is wired like the screenshot attached, the only difference being which pins the rows and columns are connected to (they are wired as per the code below).

 

As I said in the other thread where you asked, try without the "Serial.begin(9600);" line.
I think that's probably interfering with the DCS-BIOS setup of the serial port.

Link to comment
Share on other sites

  • 1 year later...
  • Recently Browsing   0 members

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