Jump to content

Arduino/DCS BIOS - 6 digit 7 segement display help


giebby

Recommended Posts

Hello fine pilots,

 

 

I have been struggling with some coding for displaying the F14B V/UHF PILOT Remote Display in Arduino. Lucky me while in the lust for learning I bought the more difficult chip to code.

 

The module I have is a: https://robotdyn.com/6-digit-led-display-tube-7-segments-74hc595.html . I ordered other display tubes with the TM1637's but it seems to be taking its sweet time from China so I am trying to make these work.

 

I found demo multiplexing code in where I can modify slightly to run a counter for all 6 digits. Here is the code I found below:

 

const int clockpin = 7; //SCK
const int latchpin = 5; //RCK 
const int datapin = 6;  //DIO
const int num_of_digits = 8;

/* Segment bit location(7=MSB, 0=LSB):
* 
*    |--0--|
*   5|     |1
*    |--6--|
*   4|     |2
*    |--3--| **7
*/

// Array with possible values(0 = segment ON, 1 = segment off)
byte value[] ={ B11000000, // 0
               B11111001, // 1
               B10100100, // 2
               B10110000, // 3
               B10011001, // 4
               B10010010, // 5
               B10000010, // 6
               B11111000, // 7
               B10000000, // 8
               B10010000, // 9
               B11111111};// display nothing

byte digit[] ={ B00010000, // left segment
               B00100000,
               B01000000,
               B10000000,
               B00000001, 
               B00000010,
               B00000100,
               B00001000 }; // right segment

void showDigit(int segmentnum, int number, bool showdecimalpoint)
{
 digitalWrite(latchpin,LOW);
 byte value_temp = value[number];
 value_temp = showdecimalpoint ? (value_temp & B01111111) : value_temp;
 shiftOut(datapin,clockpin,MSBFIRST,value_temp);
 shiftOut(datapin,clockpin,MSBFIRST,digit[segmentnum]);  
 digitalWrite(latchpin,HIGH);
}

int counter = 0;
void demoDelay()
{
 // *** Delay for demo purposes only ***
 counter++;
 if(counter <= num_of_digits)
 {
   delay(200);
 }
 else
 {
   delay(1);
   if(counter >= (num_of_digits*200))
   {
     counter = 0;
   }
 }
 // ************************************
}
               
void setup() {
 pinMode(clockpin, OUTPUT);
 pinMode(latchpin, OUTPUT);
 pinMode(datapin, OUTPUT);
}

void loop() {;
 for(int i = 0; i < num_of_digits; i++)
 {
   showDigit(i, i, true);
   demoDelay();
 }
}

I KNOW my issues stem from lack of coding xp. I have been fiddling with this for a few weeks now and have made very slow progress. The best I can do is modify existing code for the module to display slightly different. I am unsure how to incorporate this found multiplexing code with DCS BIOS and its example. I've looked for awhile (RTFM) and did a few stints at W3 schools to help understand more of C but I tend to get lost without the ability to throw questions out there.

 

Here is my code below so far get this thing to work. I am losing my mind over this as I know it is probably simple but I cannot seem to figure it out. I'd love to see if anyone can lend a few minutes to look it over. :doh::helpsmilie:

 

#define DCSBIOS_IRQ_SERIAL
#include <DcsBios.h>

const int clockpin = 7; //SCK
const int latchpin = 5; //RCK 
const int datapin = 6;  //DIO
const int num_of_digits = 6;
 
/* Segment bit location(7=MSB, 0=LSB):
* 
*    |--0--|
*   5|     |1
*    |--6--|
*   4|     |2
*    |--3--| **7
*/

// Array with possible values(0 = segment ON, 1 = segment off)
byte value[] ={ B11000000, // 0
               B11111001, // 1
               B10100100, // 2
               B10110000, // 3
               B10011001, // 4
               B10010010, // 5
               B10000010, // 6
               B11111000, // 7
               B10000000, // 8
               B10010000, // 9
               B11111111};// display nothing

byte digit[] ={ B00010000, // left segment
               B00100000,
               B01000000,
               B00000001, 
               B00000010,
               B00000100,};// right segment

void showDigit(int segmentnum, int number, bool showdecimalpoint)
{
 digitalWrite(latchpin,LOW);
 byte value_temp = value[number];
 value_temp = showdecimalpoint ? (value_temp & B01111111) : value_temp;
 shiftOut(datapin,clockpin,MSBFIRST,value_temp);
 shiftOut(datapin,clockpin,MSBFIRST,digit[segmentnum]); 
 digitalWrite(latchpin,HIGH);
}
               
void setup() {
 pinMode(clockpin, OUTPUT);
 pinMode(latchpin, OUTPUT);
 pinMode(datapin, OUTPUT);
 DcsBios::setup();
}

void onPltVuhfRemoteDispChange(char* newValue) {

//no idea what I am doing here but trying to pull the char* array into each digit
     showDigit(newValue[0]);
     showDigit(newValue[1]);
     showDigit(newValue[2]);
     showDigit(newValue[3]);
     showDigit(newValue[4]);
     showDigit(newValue[5]);
     showDigit(newValue[6]);
     showDigit(newValue[7]);
}
DcsBios::StringBuffer<7> pltVuhfRemoteDispBuffer(0x1484, onPltVuhfRemoteDispChange);



void loop() {
   DcsBios::loop();
 }


}

giebby

Link to comment
Share on other sites

I don't have too much experience in DCS-BIOS (as a matter of fact, I have my own issues to solve with it), and I have some background on C programming.

 

I am not sure if it is the cause of your problem, but I found something odd in your code; specifically in these parts:

 

void showDigit(int segmentnum, int number, bool showdecimalpoint)
{
 digitalWrite(latchpin,LOW);
 byte value_temp = value[number];
 value_temp = showdecimalpoint ? (value_temp & B01111111) : value_temp;
 shiftOut(datapin,clockpin,MSBFIRST,value_temp);
 shiftOut(datapin,clockpin,MSBFIRST,digit[segmentnum]); 
 digitalWrite(latchpin,HIGH);
}
               
....

void onPltVuhfRemoteDispChange(char* newValue) {

//no idea what I am doing here but trying to pull the char* array into each digit
     showDigit(newValue[0]);
     showDigit(newValue[1]);
     showDigit(newValue[2]);
     showDigit(newValue[3]);
     showDigit(newValue[4]);
     showDigit(newValue[5]);
     showDigit(newValue[6]);
     showDigit(newValue[7]);
}

In the first part, you are defining a showDigit function that needs three arguments (two integer numbers and a boolean - true or false), but when you define the onPltVuhfRemoteDispChange function you call showDigit passing only one argument (the value you want to be shown I assume).

If I am correct, the calls shoulb be like this:

 

showDigit(a_number (that represents the segment where you want the value to be shown), newValue[0], 1_or_0 (depending if you want to turn on the digital point, 1 for true, 0 for false);

 

So, the calls should look like these:

 

showDigit(0 /* for the first segment */, newValue[0], 0 /* no digital point */);

 

another odd thing in your code is that your display have 6 digits, but in your onPltVuhfRemoteDispChange, you are calling showDigit 8 times, if I am not mistaken, taht would be correct if you had an 8 digit segments.

 

Again, I don't have too much experience in DCS-BIOS, neither a 6 digit module to test it, but I hope my answer leads you to a possible solution.

Let me know if it is of any help.

Intel i5-7600K @3,80 (4,9 OC) + Corsair Vengeance 16GB DDR4@3200 XMP 2.0 + Cooler Master Hyper 212 LED + Asus MAXIMUS IX HERO + Thermaltake Chaser A31 Snow Edition

Geforce RTX 2060 6GB

SSD Samsung 850 EVO 500GB + HDD WDC WD500 500GB

Saitek X-52 Pro & Thrustmaster T.Flight Rudder Pedals & TrackIR 5 & Kingston HyperX Alloy FPS

Oh, yeah, also the Sony PlayStation 4 :happy:

Link to comment
Share on other sites

I took a second look to your post, and after examining your found code, now I know that your showDigit calls are lacking arguments.

Look at the found code example, when it calls showDigit in loop()

 

void loop() {;
 for(int i = 0; i < num_of_digits; i++)
 {
   showDigit(i, i, true); /*[b]<--- It is using three arguments, not one[/b]*/
   demoDelay();
 }
}

So, we can assume for sure that that is one of your problems with the code, I don't know if it is the only one, but correct that and let me know if something changed.

Intel i5-7600K @3,80 (4,9 OC) + Corsair Vengeance 16GB DDR4@3200 XMP 2.0 + Cooler Master Hyper 212 LED + Asus MAXIMUS IX HERO + Thermaltake Chaser A31 Snow Edition

Geforce RTX 2060 6GB

SSD Samsung 850 EVO 500GB + HDD WDC WD500 500GB

Saitek X-52 Pro & Thrustmaster T.Flight Rudder Pedals & TrackIR 5 & Kingston HyperX Alloy FPS

Oh, yeah, also the Sony PlayStation 4 :happy:

Link to comment
Share on other sites

I took a second look to your post, and after examining your found code, now I know that your showDigit calls are lacking arguments.

Look at the found code example, when it calls showDigit in loop()

 

void loop() {;
 for(int i = 0; i < num_of_digits; i++)
 {
   showDigit(i, i, true); /*[b]<--- It is using three arguments, not one[/b]*/
   demoDelay();
 }
}

So, we can assume for sure that that is one of your problems with the code, I don't know if it is the only one, but correct that and let me know if something changed.

 

 

Thank you for the past two posts. I appreciate it. I was trying to dive into it more before replying but I am stumped. I took your information above to heart and modified the code but now getting a primary expression error in the loop (first line of course). Thanks for taking the time to take a look.

 

 

 

#define DCSBIOS_IRQ_SERIAL
#include <DcsBios.h>

const int clockpin = 7; //SCK
const int latchpin = 5; //RCK 
const int datapin = 6;  //DIO
const int num_of_digits = 6;
 
/* Segment bit location(7=MSB, 0=LSB):
* 
*    |--0--|
*   5|     |1
*    |--6--|
*   4|     |2
*    |--3--| **7
*/

// Array with possible values(0 = segment ON, 1 = segment off)
byte value[] ={ B11000000, // 0
               B11111001, // 1
               B10100100, // 2
               B10110000, // 3
               B10011001, // 4
               B10010010, // 5
               B10000010, // 6
               B11111000, // 7
               B10000000, // 8
               B10010000, // 9
               B11111111};// display nothing

byte digit[] ={ B00010000, // left segment
               B00100000,
               B01000000,
               B00000001, 
               B00000010,
               B00000100,};// right segment

void showDigit(int segmentnum, int number, bool showdecimalpoint)
{
 digitalWrite(latchpin,LOW);
 byte value_temp = value[number];
 value_temp = showdecimalpoint ? (value_temp & B01111111) : value_temp;
 shiftOut(datapin,clockpin,MSBFIRST,value_temp);
 shiftOut(datapin,clockpin,MSBFIRST,digit[segmentnum]); 
 digitalWrite(latchpin,HIGH);
}
               
void setup() {
 pinMode(clockpin, OUTPUT);
 pinMode(latchpin, OUTPUT);
 pinMode(datapin, OUTPUT);
 DcsBios::setup();
}

void onPltVuhfRemoteDispChange(char* newValue) {

//trying to pull the char* array into each digit with the bool decimal with a delay to show the number(?)

showDigit(0,newValue[0],0);
delay(5);
showDigit(1,newValue[0],0);
delay(5);
showDigit(2,newValue[0],1);
delay(5);
showDigit(3,newValue[0],0);
delay(5);
showDigit(4,newValue[0],0);
delay(5);
showDigit(5,newValue[0],0);
delay(5);
}
DcsBios::StringBuffer<7> pltVuhfRemoteDispBuffer(0x1484, onPltVuhfRemoteDispChange);

 void loop() {;
 for(char i = * ; i < 0 ; i) //trying to push loop to show digit by saying something like if the char # is bigger then 0, display and show digit. Totally losing my self in the logic.
 {
   showDigit(i, i, true);
   
 DcsBios::loop();
}

Link to comment
Share on other sites

Ah, crap! forget about what I wrote below in this post; I haven't pay attention to the comment you put in the for loop

//trying to push loop to show digit by saying something like if the char # is bigger then 0, display and show digit. Totally losing my self in the logic.

I am leaving the text only to show you how to write a for loop, but I think I understand what you are trying to do, but since like I told I don't have a 6 digit module, I would try to make a guess and some assumptions to help you code this. In the meantime, if someone else can shed some light with this, please do so.

 

Previous text I wrote

The problem in the loop() is because the for definition is wrong.

for(char i = * ; i < 0 ; i)

The correct syntax in C for a for loop can be explained like this:

for (type variable_name_here (usually "i") = initial_value; condition_to_stop the loop; increment_or_decrement)

So, if I want a loop to run some code 5 times, it will look like:

for (int i = 1; i <= 5; i++) {
   // code to run 5 times;
}

 

You have: for(char i = *

You can use char instead of int, but you will be limited to values from 0 to 255, if your code does not need to be run more then 256 times, you can leave it as char.

The "= *" segment is incorrect, you will need a number, so I am guessing it should be "= 0" or "=1"

Then you have "i < 0", in this case it would be correct if you need the for loop to count in reverse order, but then, the first part should have a value greater than 0; taking the previous example, it would be like these if I want a code to be run 5 times but counting in reverse:

for (int i = 5; i >= 0; i--) {
   // code to run 5 times;
}

 

Finally, you end the for definition with "; i)", so you are not telling if the value of i should be incremented (i++) or decremented (i--)


Edited by ECV56_Polten

Intel i5-7600K @3,80 (4,9 OC) + Corsair Vengeance 16GB DDR4@3200 XMP 2.0 + Cooler Master Hyper 212 LED + Asus MAXIMUS IX HERO + Thermaltake Chaser A31 Snow Edition

Geforce RTX 2060 6GB

SSD Samsung 850 EVO 500GB + HDD WDC WD500 500GB

Saitek X-52 Pro & Thrustmaster T.Flight Rudder Pedals & TrackIR 5 & Kingston HyperX Alloy FPS

Oh, yeah, also the Sony PlayStation 4 :happy:

Link to comment
Share on other sites

While I examine the rest of the code, correct yours in the onPltVuhfRemoteDispChange section to this:

 

void onPltVuhfRemoteDispChange(char* newValue) {

//trying to pull the char* array into each digit with the bool decimal with a delay to show the number(?)

for (int i = 0; i < strlen(newValue); i++) {
	if (i = 2)
		showDigit(i, newValue[i], 1);
	else
		showDigit(i, newValue[i], 0);
}
}
DcsBios::StringBuffer<7> pltVuhfRemoteDispBuffer(0x1484, onPltVuhfRemoteDispChange);


Edited by ECV56_Polten
Typo

Intel i5-7600K @3,80 (4,9 OC) + Corsair Vengeance 16GB DDR4@3200 XMP 2.0 + Cooler Master Hyper 212 LED + Asus MAXIMUS IX HERO + Thermaltake Chaser A31 Snow Edition

Geforce RTX 2060 6GB

SSD Samsung 850 EVO 500GB + HDD WDC WD500 500GB

Saitek X-52 Pro & Thrustmaster T.Flight Rudder Pedals & TrackIR 5 & Kingston HyperX Alloy FPS

Oh, yeah, also the Sony PlayStation 4 :happy:

Link to comment
Share on other sites

Final code... maybe

 

Ok, I think I have it, try this code and let me know:

#define DCSBIOS_IRQ_SERIAL
#include <DcsBios.h>

const int clockpin = 7; //SCK
const int latchpin = 5; //RCK 
const int datapin = 6;  //DIO
const int num_of_digits = 6;
 
/* Segment bit location(7=MSB, 0=LSB):
* 
*    |--0--|
*   5|     |1
*    |--6--|
*   4|     |2
*    |--3--| **7
*/

// Array with possible values(0 = segment ON, 1 = segment off)
byte value[] ={ B11000000, // 0
               B11111001, // 1
               B10100100, // 2
               B10110000, // 3
               B10011001, // 4
               B10010010, // 5
               B10000010, // 6
               B11111000, // 7
               B10000000, // 8
               B10010000, // 9
               B11111111};// display nothing

byte digit[] ={ B00010000, // left segment
               B00100000,
               B01000000,
               B00000001, 
               B00000010,
               B00000100,};// right segment

void showDigit(int segmentnum, int number, bool showdecimalpoint)
{
digitalWrite(latchpin,LOW);
byte value_temp = value[number];
value_temp = showdecimalpoint ? (value_temp & B01111111) : value_temp;
shiftOut(datapin,clockpin,MSBFIRST,value_temp);
shiftOut(datapin,clockpin,MSBFIRST,digit[segmentnum]); 
digitalWrite(latchpin,HIGH);
}
               
void setup() {
pinMode(clockpin, OUTPUT);
pinMode(latchpin, OUTPUT);
pinMode(datapin, OUTPUT);
DcsBios::setup();
}

void onPltVuhfRemoteDispChange(char* newValue) {
//trying to pull the char* array into each digit with the bool decimal with a delay to show the number(?)
if (atoi(newValue) > 0) {
	for (int i = 0; i < strlen(newValue); i++) {
		if (i = 2)
			showDigit(i, atoi(newValue[i]), 1);
		else
			showDigit(i, atoi(newValue[i]), 0);
	}
}
}
DcsBios::StringBuffer<7> pltVuhfRemoteDispBuffer(0x1484, onPltVuhfRemoteDispChange);

void loop() {
DcsBios::loop();
}

 

For what I have been reading when you TM1637 arrive it will be way much easier to code.


Edited by ECV56_Polten

Intel i5-7600K @3,80 (4,9 OC) + Corsair Vengeance 16GB DDR4@3200 XMP 2.0 + Cooler Master Hyper 212 LED + Asus MAXIMUS IX HERO + Thermaltake Chaser A31 Snow Edition

Geforce RTX 2060 6GB

SSD Samsung 850 EVO 500GB + HDD WDC WD500 500GB

Saitek X-52 Pro & Thrustmaster T.Flight Rudder Pedals & TrackIR 5 & Kingston HyperX Alloy FPS

Oh, yeah, also the Sony PlayStation 4 :happy:

Link to comment
Share on other sites

Ok, I think I have it, try this code and let me know:

#define DCSBIOS_IRQ_SERIAL
#include <DcsBios.h>

const int clockpin = 7; //SCK
const int latchpin = 5; //RCK 
const int datapin = 6;  //DIO
const int num_of_digits = 6;
 
/* Segment bit location(7=MSB, 0=LSB):
* 
*    |--0--|
*   5|     |1
*    |--6--|
*   4|     |2
*    |--3--| **7
*/

// Array with possible values(0 = segment ON, 1 = segment off)
byte value[] ={ B11000000, // 0
               B11111001, // 1
               B10100100, // 2
               B10110000, // 3
               B10011001, // 4
               B10010010, // 5
               B10000010, // 6
               B11111000, // 7
               B10000000, // 8
               B10010000, // 9
               B11111111};// display nothing

byte digit[] ={ B00010000, // left segment
               B00100000,
               B01000000,
               B00000001, 
               B00000010,
               B00000100,};// right segment

void showDigit(int segmentnum, int number, bool showdecimalpoint)
{
   digitalWrite(latchpin,LOW);
   byte value_temp = value[number];
   value_temp = showdecimalpoint ? (value_temp & B01111111) : value_temp;
   shiftOut(datapin,clockpin,MSBFIRST,value_temp);
   shiftOut(datapin,clockpin,MSBFIRST,digit[segmentnum]); 
   digitalWrite(latchpin,HIGH);
}
               
void setup() {
   pinMode(clockpin, OUTPUT);
   pinMode(latchpin, OUTPUT);
   pinMode(datapin, OUTPUT);
   DcsBios::setup();
}

void onPltVuhfRemoteDispChange(char* newValue) {
   //trying to pull the char* array into each digit with the bool decimal with a delay to show the number(?)
   if (atoi(newValue) > 0) {
       for (int i = 0; i < strlen(newValue); i++) {
           if (i = 2)
               showDigit(i, atoi(newValue[i]), 1);
           else
               showDigit(i, atoi(newValue[i]), 0);
       }
   }
}
DcsBios::StringBuffer<7> pltVuhfRemoteDispBuffer(0x1484, onPltVuhfRemoteDispChange);

void loop() {
   DcsBios::loop();
}

For what I have been reading when you TM1637 arrive it will be way much easier to code.

 

 

Hello!

 

 

Thank you for your continued help. I almost threw in the towel and decided to wait for the TM's but guess what, they cancelled my order. LOL Now to order from another store and wait the 90 days..

 

 

I ran the code presented above. There were some compiling errors but it did write to the Arduino. During initial power on the display is blank (perfect) but when I transmit the frequency (DCS-BIOS Debugger) it only has one digit displaying. It is the 3rd digit as a 0 with the bool (decimal).

 

 

Compiling error is below:

 

 

C:\Users\AL\Documents\Arduino\DCS_VUHF_F14_Remote_Display\DCS_VUHF_F14_Remote_Display_v2\DCS_VUHF_F14_Remote_Display_v2.ino: In function 'void onPltVuhfRemoteDispChange(char*)':
C:\Users\AL\Documents\Arduino\DCS_VUHF_F14_Remote_Display\DCS_VUHF_F14_Remote_Display_v2\DCS_VUHF_F14_Remote_Display_v2.ino:60:37: warning: invalid conversion from 'char' to 'const char*' [-fpermissive]
        showDigit(i, atoi(newValue[i]), 1);
                          ~~~~~~~~~~^
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:23:0,
                from sketch\DCS_VUHF_F14_Remote_Display_v2.ino.cpp:1:
c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdlib.h:276:12: note:   initializing argument 1 of 'int atoi(const char*)'
extern int atoi(const char *__s) __ATTR_PURE__;
           ^~~~
C:\Users\AL\Documents\Arduino\DCS_VUHF_F14_Remote_Display\DCS_VUHF_F14_Remote_Display_v2\DCS_VUHF_F14_Remote_Display_v2.ino:62:37: warning: invalid conversion from 'char' to 'const char*' [-fpermissive]
        showDigit(i, atoi(newValue[i]), 0);
                          ~~~~~~~~~~^
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:23:0,
                from sketch\DCS_VUHF_F14_Remote_Display_v2.ino.cpp:1:
c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdlib.h:276:12: note:   initializing argument 1 of 'int atoi(const char*)'
extern int atoi(const char *__s) __ATTR_PURE__;
           ^~~~
Sketch uses 2932 bytes (1%) of program storage space. Maximum is 253952 bytes.
Global variables use 149 bytes (1%) of dynamic memory, leaving 8043 bytes for local variables. Maximum is 8192 bytes.

Link to comment
Share on other sites

Mmm. that's odd, when I compiled the code in my Arduino IDE it showed no errors or warnings.

Just as a test, change the definition of onPltVuhfRemoteDispChange to this:

void onPltVuhfRemoteDispChange(char* newValue) {
//trying to pull the char* array into each digit with the bool decimal with a delay to show the number(?)
if (atoi(newValue) > 0) {
	for (int i = 0; i < strlen(newValue); i++) {
		if (i = 2)
			showDigit(i, newValue[i] - 48, 1); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
		else
			showDigit(i, newValue[i] - 48, 0); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
	}
}
}
DcsBios::StringBuffer<7> pltVuhfRemoteDispBuffer(0x1484, onPltVuhfRemoteDispChange);


Edited by ECV56_Polten

Intel i5-7600K @3,80 (4,9 OC) + Corsair Vengeance 16GB DDR4@3200 XMP 2.0 + Cooler Master Hyper 212 LED + Asus MAXIMUS IX HERO + Thermaltake Chaser A31 Snow Edition

Geforce RTX 2060 6GB

SSD Samsung 850 EVO 500GB + HDD WDC WD500 500GB

Saitek X-52 Pro & Thrustmaster T.Flight Rudder Pedals & TrackIR 5 & Kingston HyperX Alloy FPS

Oh, yeah, also the Sony PlayStation 4 :happy:

Link to comment
Share on other sites

If the code above still don't work, then, try this

 

void onPltVuhfRemoteDispChange(char* newValue) {
//trying to pull the char* array into each digit with the bool decimal with a delay to show the number(?)
if (atoi(newValue) > 0) {
	for (int i = 0; i < strlen(newValue); i++) {
		if (i = 2)
			showDigit(i, String(newValue[i]).toInt(), 1);
		else
			showDigit(i, String(newValue[i]).toInt(), 0);
	}
}
}
DcsBios::StringBuffer<7> pltVuhfRemoteDispBuffer(0x1484, onPltVuhfRemoteDispChange);

Intel i5-7600K @3,80 (4,9 OC) + Corsair Vengeance 16GB DDR4@3200 XMP 2.0 + Cooler Master Hyper 212 LED + Asus MAXIMUS IX HERO + Thermaltake Chaser A31 Snow Edition

Geforce RTX 2060 6GB

SSD Samsung 850 EVO 500GB + HDD WDC WD500 500GB

Saitek X-52 Pro & Thrustmaster T.Flight Rudder Pedals & TrackIR 5 & Kingston HyperX Alloy FPS

Oh, yeah, also the Sony PlayStation 4 :happy:

Link to comment
Share on other sites

Mmm. that's odd, when I compiled the code in my Arduino IDE it showed no errors or warnings.

Just as a test, change the definition of onPltVuhfRemoteDispChange to this:

void onPltVuhfRemoteDispChange(char* newValue) {
   //trying to pull the char* array into each digit with the bool decimal with a delay to show the number(?)
   if (atoi(newValue) > 0) {
       for (int i = 0; i < strlen(newValue); i++) {
           if (i = 2)
               showDigit(i, newValue[i] - 48, 1); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
           else
               showDigit(i, newValue[i] - 48, 0); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
       }
   }
}
DcsBios::StringBuffer<7> pltVuhfRemoteDispBuffer(0x1484, onPltVuhfRemoteDispChange);

 

 

Well we have some success in this code above my friend. I am getting most numbers displaying now with the example code above (and make changes in the debugger for them to display! YAY!). With some modifications of course (code below) I have an issue with the bool. Currently with my code now, the 4th digit is always displaying the number 6. I ran a few tests with some different number combinations and it appears that the code is having a hard time with the bool. The 5th digit seems to be what the 4th digit should be so that leads me to believe it is something with the bool. Also, on the bool subject, I am showing bool (decimal) on all digits except 0. What I am seeing on my display is exampled below

 

Example on display: 13.3.6.1.0. when the call should be 133.105

 

 

I need to buy you lots of beers. I know it is almost there. Oh man... :thumbup:

 

 

#define DCSBIOS_IRQ_SERIAL
#include <DcsBios.h>

const int clockpin = 7; //SCK
const int latchpin = 5; //RCK 
const int datapin = 6;  //DIO
const int num_of_digits = 6;
 
/* Segment bit location(7=MSB, 0=LSB):
* 
*    |--0--|
*   5|     |1
*    |--6--|
*   4|     |2
*    |--3--| **7
*/

// Array with possible values(0 = segment ON, 1 = segment off)
byte value[] ={ B11000000, // 0
               B11111001, // 1
               B10100100, // 2
               B10110000, // 3
               B10011001, // 4
               B10010010, // 5
               B10000010, // 6
               B11111000, // 7
               B10000000, // 8
               B10010000, // 9
               B11111111};// display nothing

byte digit[] ={ B00010000, // left segment
               B00100000,
               B01000000,
               B00000001, 
               B00000010,
               B00000100,};// right segment

void showDigit(int segmentnum, int number, bool showdecimalpoint)
{
 digitalWrite(latchpin,LOW);
 byte value_temp = value[number];
 value_temp = showdecimalpoint ? (value_temp & B01111111) : value_temp;
 shiftOut(datapin,clockpin,MSBFIRST,value_temp);
 shiftOut(datapin,clockpin,MSBFIRST,digit[segmentnum]); 
 digitalWrite(latchpin,HIGH);
}
               
void setup() {
 pinMode(clockpin, OUTPUT);
 pinMode(latchpin, OUTPUT);
 pinMode(datapin, OUTPUT);
 DcsBios::setup();
}

void onPltVuhfRemoteDispChange(char* newValue) {
 //trying to pull the char* array into each digit with the bool decimal with a delay to show the number(?)
 if (atoi(newValue) > 0) {
   for (int i = 0; i < strlen(newValue); i++) {

           if (i = 0)
       showDigit(i, newValue[i] - 48, 1); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
     else
       showDigit(i, newValue[i] - 48, 0); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0

           if (i = 1)
       showDigit(i, newValue[i] - 48, 1); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
     else
       showDigit(i, newValue[i] - 48, 0); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
     
           if (i = 2)
       showDigit(i, newValue[i] - 48, 1); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
     else
       showDigit(i, newValue[i] - 48, 0); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0

           if (i = 3)
       showDigit(i, newValue[i] - 48, 1); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
     else
       showDigit(i, newValue[i] - 48, 0); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
 
           if (i = 4)
       showDigit(i, newValue[i] - 48, 1); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
     else
       showDigit(i, newValue[i] - 48, 0); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0

           if (i = 5)
       showDigit(i, newValue[i] - 48, 1); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
     else
       showDigit(i, newValue[i] - 48, 0); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
   }
 }
}
DcsBios::StringBuffer<7> pltVuhfRemoteDispBuffer(0x1484, onPltVuhfRemoteDispChange);


void loop() {
 DcsBios::loop();
}

Link to comment
Share on other sites

I am at the office right now, so I can not give you a thorough response, but your code is showing so many decimal points because the "if" blocks are all "true" at some point in the execution.

 

Yesterday night I run some tests in an LCD 1602 I2C display; based on the results I think the code will require some minor changes.

 

I will try to get back at this as soon as I can, in the meantime don't give up, and I suggest you get some good book or tutorial about C programming or Arduino programming, you need a better understanding of the programming logic.

Intel i5-7600K @3,80 (4,9 OC) + Corsair Vengeance 16GB DDR4@3200 XMP 2.0 + Cooler Master Hyper 212 LED + Asus MAXIMUS IX HERO + Thermaltake Chaser A31 Snow Edition

Geforce RTX 2060 6GB

SSD Samsung 850 EVO 500GB + HDD WDC WD500 500GB

Saitek X-52 Pro & Thrustmaster T.Flight Rudder Pedals & TrackIR 5 & Kingston HyperX Alloy FPS

Oh, yeah, also the Sony PlayStation 4 :happy:

Link to comment
Share on other sites

I am at the office right now, so I can not give you a thorough response, but your code is showing so many decimal points because the "if" blocks are all "true" at some point in the execution.

 

Yesterday night I run some tests in an LCD 1602 I2C display; based on the results I think the code will require some minor changes.

 

I will try to get back at this as soon as I can, in the meantime don't give up, and I suggest you get some good book or tutorial about C programming or Arduino programming, you need a better understanding of the programming logic.

 

 

 

 

I was able to clear up the decimals and now working on the random number on digit 3. It is always presenting the number 6 with a bool (decimal). Not 100% why but I am going to fiddle with it and see what I can come up with.

Link to comment
Share on other sites

Try this code; if it works, I will celebrate with a glass of my finest whiskey, if not, I will drown my sorrow in a glass of my finest whiskey ;-)

#define DCSBIOS_IRQ_SERIAL
#include <DcsBios.h>

const int clockpin = 7; //SCK
const int latchpin = 5; //RCK 
const int datapin = 6;  //DIO
const int num_of_digits = 6;
 
/* Segment bit location(7=MSB, 0=LSB):
* 
*    |--0--|
*   5|     |1
*    |--6--|
*   4|     |2
*    |--3--| **7
*/

// Array with possible values(0 = segment ON, 1 = segment off)
byte value[] ={ B11000000, // 0
               B11111001, // 1
               B10100100, // 2
               B10110000, // 3
               B10011001, // 4
               B10010010, // 5
               B10000010, // 6
               B11111000, // 7
               B10000000, // 8
               B10010000, // 9
               B11111111};// display nothing

byte digit[] ={ B00010000, // left segment
               B00100000,
               B01000000,
               B00000001, 
               B00000010,
               B00000100,};// right segment

void showDigit(int segmentnum, int number, bool showdecimalpoint)
{
 digitalWrite(latchpin,LOW);
 byte value_temp = value[number];
 value_temp = showdecimalpoint ? (value_temp & B01111111) : value_temp;
 shiftOut(datapin,clockpin,MSBFIRST,value_temp);
 shiftOut(datapin,clockpin,MSBFIRST,digit[segmentnum]); 
 digitalWrite(latchpin,HIGH);
}
               
void setup() {
 pinMode(clockpin, OUTPUT);
 pinMode(latchpin, OUTPUT);
 pinMode(datapin, OUTPUT);
 DcsBios::setup();
}

void loop() {;
 DcsBios::loop();
}

void onPltVuhfRemoteDispChange(char* newValue) {
 int lenNewValue = String(newValue).length(); // get the length of newValue
 if (String(newValue).indexOf('.') >= 0) {
   lenNewValue--; // if newValue has a decimal point, I substract 1 to lenNewValue
 }
 // get the position of the decimal point and substract 1 to pair it with the segment position of the preceding number
 int pointPos = String(newValue).indexOf('.') - 1;
 // if the value to display does not contain a decimal point indexOf will return -1 so pointPos would be -2 in that case
 
 if (lenNewValue < num_of_digits) {
   for (int i = 0; i < lenNewValue; i++) {
     showDigit(i, 10, 0); // this will display nothing in the first segments if the length of newValue has less tnan 6 digits
   }
 }
 for (int i = num_of_digits - 1; i >= (num_of_digits - lenNewValue); i--) {
   if (i == pointPos + (num_of_digits - lenNewValue)) {
     showDigit(i, String(newValue[i - (num_of_digits - lenNewValue)]).toInt(), 1); // toInt() will convert the char to an integer value since showDigit expect this type as second parameter (for example, it will convert the char '5' - which has a value of 53 in the ASCII table, to 5
   }
   else {
     showDigit(i, String(newValue[i - (num_of_digits - lenNewValue)]).toInt(), 0); // otherwise, only turn on the segments of the digit to display only
   }
 }
}
DcsBios::StringBuffer<7> pltVuhfRemoteDispBuffer(0x1484, onPltVuhfRemoteDispChange);


Edited by ECV56_Polten

Intel i5-7600K @3,80 (4,9 OC) + Corsair Vengeance 16GB DDR4@3200 XMP 2.0 + Cooler Master Hyper 212 LED + Asus MAXIMUS IX HERO + Thermaltake Chaser A31 Snow Edition

Geforce RTX 2060 6GB

SSD Samsung 850 EVO 500GB + HDD WDC WD500 500GB

Saitek X-52 Pro & Thrustmaster T.Flight Rudder Pedals & TrackIR 5 & Kingston HyperX Alloy FPS

Oh, yeah, also the Sony PlayStation 4 :happy:

Link to comment
Share on other sites

Try this code; if it works, I will celebrate with a glass of my finest whiskey, if not, I will drown my sorrow in a glass of my finest whiskey ;-)

#define DCSBIOS_IRQ_SERIAL
#include <DcsBios.h>

const int clockpin = 7; //SCK
const int latchpin = 5; //RCK 
const int datapin = 6;  //DIO
const int num_of_digits = 6;
 
/* Segment bit location(7=MSB, 0=LSB):
* 
*    |--0--|
*   5|     |1
*    |--6--|
*   4|     |2
*    |--3--| **7
*/

// Array with possible values(0 = segment ON, 1 = segment off)
byte value[] ={ B11000000, // 0
               B11111001, // 1
               B10100100, // 2
               B10110000, // 3
               B10011001, // 4
               B10010010, // 5
               B10000010, // 6
               B11111000, // 7
               B10000000, // 8
               B10010000, // 9
               B11111111};// display nothing

byte digit[] ={ B00010000, // left segment
               B00100000,
               B01000000,
               B00000001, 
               B00000010,
               B00000100,};// right segment

void showDigit(int segmentnum, int number, bool showdecimalpoint)
{
 digitalWrite(latchpin,LOW);
 byte value_temp = value[number];
 value_temp = showdecimalpoint ? (value_temp & B01111111) : value_temp;
 shiftOut(datapin,clockpin,MSBFIRST,value_temp);
 shiftOut(datapin,clockpin,MSBFIRST,digit[segmentnum]); 
 digitalWrite(latchpin,HIGH);
}
               
void setup() {
 pinMode(clockpin, OUTPUT);
 pinMode(latchpin, OUTPUT);
 pinMode(datapin, OUTPUT);
 DcsBios::setup();
}

void loop() {;
 DcsBios::loop();
}

void onPltVuhfRemoteDispChange(char* newValue) {
 int lenNewValue = String(newValue).length(); // get the length of newValue
 if (String(newValue).indexOf('.') >= 0) {
   lenNewValue--; // if newValue has a decimal point, I substract 1 to lenNewValue
 }
 // get the position of the decimal point and substract 1 to pair it with the segment position of the preceding number
 int pointPos = String(newValue).indexOf('.') - 1;
 // if the value to display does not contain a decimal point indexOf will return -1 so pointPos would be -2 in that case
 
 if (lenNewValue < num_of_digits) {
   for (int i = 0; i < lenNewValue; i++) {
     showDigit(i, 10, 0); // this will display nothing in the first segments if the length of newValue has less tnan 6 digits
   }
 }
 for (int i = num_of_digits - 1; i >= (num_of_digits - lenNewValue); i--) {
   if (i == pointPos + (num_of_digits - lenNewValue)) {
     showDigit(i, String(newValue[i - (num_of_digits - lenNewValue)]).toInt(), 1); // toInt() will convert the char to an integer value since showDigit expect this type as second parameter (for example, it will convert the char '5' - which has a value of 53 in the ASCII table, to 5
   }
   else {
     showDigit(i, String(newValue[i - (num_of_digits - lenNewValue)]).toInt(), 0); // otherwise, only turn on the segments of the digit to display only
   }
 }
}
DcsBios::StringBuffer<7> pltVuhfRemoteDispBuffer(0x1484, onPltVuhfRemoteDispChange);

 

 

Hehe Whiskey is my go-to when I drink as well :)

 

 

Code wise, The above might have been a step back. I get a flash of all digits and then just get a #1 displaying on digit 0.

 

 

-------------------------------------------

 

 

I found something interesting with the previous code. It is working partially. I can get it to display after coaxing it to work. It is also related to the extra digit. Let me explain below by the steps I do to get it to work.

 

 

 

-Freshly uploaded sketch to arduino

-I enter a string of 125.500 in DCSBIOS debugger

-Connect. Display goes all blank except digit 5 (last one) which is an "A"

-Change string in debugger to 125500 (no decimal) and it displays properly with decimal

 

-Change string in debuger to another random number and displays properly with decimal and accepts changes

 

 

 

Now here is where it gets weird. I think "OK, the debugger doesn't like me putting in manual decimals. Let's try it without." It seems to have a harder time with it now.

 

 

 

 

 

-Freshly uploaded sketch to arduino

-Enter a string of 125500 in DCSBIOS debugger (no decimal)

-Connect. Display goes all blank again except digit 5 (last one) which is an "A" again.

-Change string in debuger to another random number without decimal. NO CHANGE

-Change string in debuger to random number WITH decimal. Display shows all digits with extra number as before. (example: 125.6.52 when should be 125.520)

 

-Change string to another random number in debuger WITHOUT decimal. Display is now working and accepting string changes.

 

 

I am suspecting that this might have to do something with a "clear display" type of command? I tried some digitalwrite latchpin HIGH commands but it didn't want to seem to compile. I was trying to write something to tell the display to turn off or refresh itself before writing the new string... but what do I know... oh man..

 

 

Thanks again boss

 

 

 

 

(my partially working code from previous post you helped with)

 

#define DCSBIOS_IRQ_SERIAL
#include <DcsBios.h>

const int clockpin = 7; //SCK
const int latchpin = 5; //RCK 
const int datapin = 6;  //DIO
const int num_of_digits = 6;
 
/* Segment bit location(7=MSB, 0=LSB):
* 
*    |--0--|
*   5|     |1
*    |--6--|
*   4|     |2
*    |--3--| **7
*/

// Array with possible values(0 = segment ON, 1 = segment off)
byte value[] ={ B11000000, // 0
               B11111001, // 1
               B10100100, // 2
               B10110000, // 3
               B10011001, // 4
               B10010010, // 5
               B10000010, // 6
               B11111000, // 7
               B10000000, // 8
               B10010000, // 9
               B11111111,};// display nothing

byte digit[] ={ B00010000, // left segment
               B00100000,
               B01000000,
               B00000001, 
               B00000010,
               B00000100,};// right segment

void showDigit(int segmentnum, int number, bool showdecimalpoint)
{
 digitalWrite(latchpin,LOW);
 byte value_temp = value[number];
 value_temp = showdecimalpoint ? (value_temp & B01111111) : value_temp;
 shiftOut(datapin,clockpin,MSBFIRST,value_temp);
 shiftOut(datapin,clockpin,MSBFIRST,digit[segmentnum]); 
 digitalWrite(latchpin,HIGH);
}
               
void setup() {
 pinMode(clockpin, OUTPUT);
 pinMode(latchpin, OUTPUT);
 pinMode(datapin, OUTPUT);
 DcsBios::setup();
 
}

void onPltVuhfRemoteDispChange(char* newValue) {
 //trying to pull the char* array into each digit with the bool decimal with a delay to show the number(?)

 
 if (atoi(newValue) > 0) {
   for (int i = 0; i < strlen(newValue); i++) {

     if (i = 0)
       showDigit(i, newValue[i] - 48, 0); // atoi function removed and char converted to int as shown in https://forum.arduino.cc/index.php?topic=443605.0
     else
       showDigit(i, newValue[i] - 48, 0); 

     if (i = 1)
       showDigit(i, newValue[i] - 48, 0); 
     else
       showDigit(i, newValue[i] - 48, 0); 
     
     if (i = 2)
       showDigit(i, newValue[i] - 48, 1);
     else
       showDigit(i, newValue[i] - 48, 0); 

     if (i = 3)
       showDigit(i, newValue[i] - 48, 0); 
     else
       showDigit(i, newValue[i] - 48, 0); 
 
     if (i = 4)
       showDigit(i, newValue[i] - 48, 0); 
     else
       showDigit(i, newValue[i] - 48, 0); 

     if (i = 5)
       showDigit(i, newValue[i] - 48, 0);
     else
       showDigit(i, newValue[i] - 48, 0); 
   }
 }
}
DcsBios::StringBuffer<7> pltVuhfRemoteDispBuffer(0x1484, onPltVuhfRemoteDispChange);


void loop() {
 DcsBios::loop();
}

Link to comment
Share on other sites

I have been away from the forum these days, hence the delay answering this thread.

First of all, you must correct your "if" blocks in the onPltVuhfRemoteDispChange segment, because you are using the wrong operator.

When you use "=" you are assigning a value to a variable, so, when you write

 if (i = 0)
       showDigit(i, newValue[i] - 48, 0); 

what you are telling there, is assign the value 0 to variable i, then evaluate if the value of i is true or false (since i = 0, it will be false; any integer value greater than 0 is true) and it will not run the showdigit part of the code.

The correct operator is "==", which is the equality operator. Taking the same example, you should write it like:

 if (i == 0)
       showDigit(i, newValue[i] - 48, 0); 

Then you need to change all the "=" in your if blocks to "==". I have reread my responses, and made this same mistake in almost all of them, sorry for that.

 

You can read about C language operator in https://www.programiz.com/c-programming/c-operators.

Once again, I advice you to get a good C programming or Arduino programming book, and/or watch some tutorials about it in Youtube.


Edited by ECV56_Polten
Typo

Intel i5-7600K @3,80 (4,9 OC) + Corsair Vengeance 16GB DDR4@3200 XMP 2.0 + Cooler Master Hyper 212 LED + Asus MAXIMUS IX HERO + Thermaltake Chaser A31 Snow Edition

Geforce RTX 2060 6GB

SSD Samsung 850 EVO 500GB + HDD WDC WD500 500GB

Saitek X-52 Pro & Thrustmaster T.Flight Rudder Pedals & TrackIR 5 & Kingston HyperX Alloy FPS

Oh, yeah, also the Sony PlayStation 4 :happy:

Link to comment
Share on other sites

  • 2 years later...

@giebby Did you ever get this working? I have an LED with the same chipset

 

F-14B, F-16, F-18C, A-10C, F-5E, F-86, FC3, BF-109, FW-190, P-51, Spitfire, UH-1,AJS-37 Viggen, MIG-15, MIG-19, MIG-21, AV-8B Harrier, P-47D

Persian Gulf, Caucuses, NTTR, Normandy, The Channel, Syria

Combined Arms, WWII Assets,Super Carrier

TM Warthog, Virpil VFX,BuddyFox UFC, Saitek Pro Flight quadrant & Switch Panel, Odyssey+ VR, Jet Pad w/ SSA, Voice Attack w/Viacom Pro

GeForce RTX2080TI OC, Intel Core i7-7700K 4.5Ghz, 64GB DDR4, Dedicated 1TB SSD

Link to comment
Share on other sites

  • Recently Browsing   0 members

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