Jump to content

Problem with DCS Bios and Arduino


Recommended Posts

Hey Guys,

 

I ran into a problem with my project with DCS BIOS and Arduino

I am currently building the FA-18C UFC and have trouble with the 2 16-segment displays. They both are wired up for multiplexing with the anodes wired up on pin 31-47 and the cathodes on 48 and 49. The encoding for the numbers and letter as well as the wiring have been tested and work just fine.

The problem starts when I try to get the displays to display the values, I receive form DCS BIOS. My current suspicion is that the methods that come with DCS BIOS are not called in the correct way or not at all since despite what code I put in them it doesn’t seem to get executed. But since I am new to Arduino and C I can not rule out that I made a mistake in my code. Therefore, I add my sketch below and I would really appreciate if someone with a little more experience could take a look at it and tell me if its my code or if there is a problem with DCS BIOS.

 

As to what my thoughts where regarding the script.

I encoded the different segments and binary codes of the numbers and letter the displays have to show. Then initialized the pins and put a routine in the loop that reads out the current digit that should be displayed grabs the binary encoding and sets the right pins active first for the first display than for the second. (currently they would both show the same but it takes only one a additional variable to fix that. In the methods that DCS Bios supplies I tried to get the char that is forwarded form DCS and determine witch one it is than setting a global variable that the loop can use to display the right letter. (I suspect the mistake laying somewhere in how I process the char from DCS but I tried it with if and switch cases and didn’t manage to get either to work so your help would be highly appreciated.

 

#define DCSBIOS_RS485_SLAVE 7
#define TXENABLE_PIN 2

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

int chnr;
const int CH1 = 48;
const int CH2 = 49;

const int segmente[17] = {31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 0};
const long bitCode[26] = {
19205,     //0
18432,    //1
25345, //2 
26881, //3
26628,    //4
10501, //5
11012,   //6
18433, //7
27397, //8
26629, //9
19253, //10
18480,  //11
25393, //12
26929, //13
26676,  //14
10549, //15
11060,  //16
18481, //17
27445, //18
26677, //19
50651, //20
10675, //G
51256, //M
435, //C
14739, //S
0,};

void setup() {
DcsBios::setup();

pinMode(CH1, OUTPUT);
digitalWrite(CH1, HIGH);

pinMode(CH2, OUTPUT);
digitalWrite(CH2, HIGH);

for (int i = 0; i < 16; i++){
   pinMode(segmente[i], OUTPUT);
   digitalWrite(segmente[i], LOW);
 }
}

void loop() {
 DcsBios::loop();  
/*
 for(int i = 0; i < 16; i++) {
   digitalWrite(segmente[i], HIGH);
 }
 */
 
 for (int i = 0; i < 16; i++){
  digitalWrite(segmente[i], LOW);
 }
 digitalWrite(CH1, LOW);
 digitalWrite(CH2, HIGH);
 
 for (int i = 0;i < 16; i++) {
   if (bitRead(bitCode[chnr], i) == 1) {
   digitalWrite(segmente[i], HIGH);
   }
 }
 digitalWrite(CH1, HIGH);
 digitalWrite(CH2, LOW);

 for (int i = 0;i < 16; i++) {
   if (bitRead(bitCode[chnr], i) == 1) {
   digitalWrite(segmente[i], HIGH);
  }
 } 
}

void onufcComm1DisplayChange(char* newValue) {         
       if (newValue[0] == '1') {
         chnr = 1;
       } else {
         if(newValue[0] == '2') {
           chnr = 2;
         } else {
           if(newValue[0] == '3') {
             chnr = 3; 
           } else {
             if(newValue[0] == '4') {
               chnr = 4;
             } else {
               if(newValue[0] == '5') {
                 chnr = 5;
               } else {
                 if(newValue[0] == '6') {
                    chnr = 6;
                 } else {
                   if(newValue[0] == '7') {
                     chnr = 7;
                   } else {
                     if(newValue[0] == '8') {
                       chnr = 8;
                     } else {
                       if(newValue[0] == '9') {
                         chnr = 9;
                       }
                     }
                   }
                 }
               }
             }
           }
         } 
       }             
}
DcsBios::StringBuffer<2> ufcComm1DisplayBuffer(0x7424, onufcComm1DisplayChange);

void onufcComm2DisplayChange(char* newValue) {   
       if (newValue[1] == '1') {
         chnr = 1;
       } else {
         if(newValue[1] == '2') {
           chnr = 2;
         } else {
           if(newValue[1] == '3') {
             chnr = 3; 
           } else {
             if(newValue[1] == '4') {
               chnr = 4;
             } else {
               if(newValue[1] == '5') {
                 chnr = 5;
               } else {
                 if(newValue[1] == '6') {
                    chnr = 6;
                 } else {
                   if(newValue[1] == '7') {
                     chnr = 7;
                   } else {
                     if(newValue[1] == '8') {
                       chnr = 8;
                     } else {
                       if(newValue[1] == '9') {
                         chnr = 9;
                       }
                     }
                   }
                 }
               }
             }
           }
         }
       }
}
DcsBios::StringBuffer<2> ufcComm2DisplayBuffer(0x7426, onufcComm2DisplayChange);

 

Greeting Sky.

Link to comment
Share on other sites

  • 6 months later...
  • Recently Browsing   0 members

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