I have a problem with printing on 4 digit 7 segment display with cd4511

Hello. I made e circuit of 2 temp readers print on a 4 digit 7 segment display 1 each temp .. i have cd4511 for multiplexing 1 each set of 4 digits and i cannot print the right temperatures the values from the temp in code take the right temperature but when it comes to printing 1 set is showing the temperature fine but the other shows it doubled, instead of 24c shows 48c ... And i also dont know how to print minus temperatures and the Celsius sign please help me ive tryed everything ... Also on minus temperatures the set of digits shows random numbers and not the correct minus value ... if you check the serial monitor the Temps are correct but on the 2nd set of displays doesnt

Here is my circuit in Tinkercad: https://www.tinkercad.com/things/lpp463UJCjg

The C is fixed because i couldnt find a way to be printed i also want to print the minus sign

My Code:

int temperature;
int temperature2;
// Arduino pins connected to the 4511
const uint8_t LedA = 5;
const uint8_t LedB = 8;
const uint8_t LedC = 7;
const uint8_t LedD = 6;
const uint8_t LeA = 9;
const uint8_t LeB = 10;
const uint8_t LeC = 11;
const uint8_t LeD = 12;

// Arduino pins connected to the segment driver transistors
const uint8_t Led1 = 13;
const uint8_t Led2 = 2;
const uint8_t Led3 = 3;
const uint8_t Led4 = 4;
const uint8_t Led5 = A2;
const uint8_t Led6 = A3;
const uint8_t Led7 = A4;
const uint8_t Led8 = A5;
void setup()
{
  // Let the Arduino know which pins go where
  pinMode(LedA, OUTPUT);
  pinMode(LedB, OUTPUT);
  pinMode(LedC, OUTPUT);
  pinMode(LedD, OUTPUT);
  pinMode(LeA, OUTPUT);
  pinMode(LeB, OUTPUT);
  pinMode(LeC, OUTPUT);
  pinMode(LeD, OUTPUT);

  pinMode(Led1, OUTPUT);
  pinMode(Led2, OUTPUT);
  pinMode(Led3, OUTPUT);
  pinMode(Led4, OUTPUT);
  pinMode(Led5, OUTPUT);
  pinMode(Led6, OUTPUT);
  pinMode(Led7, OUTPUT);
  pinMode(Led8, OUTPUT);

  
  digitalWrite(Led1, LOW);
  digitalWrite(Led2, LOW);
  digitalWrite(Led3, LOW);
  digitalWrite(Led4, LOW);
  digitalWrite(Led5, LOW);
  digitalWrite(Led6, LOW);
  digitalWrite(Led7, LOW);
  digitalWrite(Led8, LOW);
      
  Serial.begin(9600);

}

void loop()
{

temperature = -40 + 0.488155 * (analogRead(A0) - 20);
temperature2 =  -40 + 0.488155  * (analogRead(A1) - 20);
 print_number(temperature);
 print_number2(temperature2);
  Serial.print ("IN ");
  Serial.print(temperature);
  Serial.println(" C");
  Serial.print ("OUT ");
  Serial.print(temperature2);
  Serial.println(" C");

}
void print_number(unsigned i) {
  static int l = 2;
  
  set_digit(Led3, l, i/10 );
  set_digit(Led2, l, i/1  );
}

void print_number2(unsigned n) {
  static int d = 1;
  
  set_digit2(Led7, d, n/10 );
  set_digit2(Led6, d, n/1  );
}

void set_digit(const uint8_t sec, const unsigned l, const unsigned value) {
  set_number(value);
  digitalWrite(sec, HIGH);
  delay(l);
  digitalWrite(sec, LOW);
}

void set_digit2(const uint8_t led, const unsigned d, const unsigned value2) {
  set_number2(value2);
  digitalWrite(led, HIGH);
  delay(d);
  digitalWrite(led, LOW);
}


void set_number(const unsigned i) {
  static const struct number {
    uint8_t d;
    uint8_t c;
    uint8_t b;
    uint8_t a;
  } numbers[] = {
    { LOW,  LOW,  LOW,  LOW}, /* 0 */
    { LOW,  LOW,  LOW, HIGH}, /* 1 */
    { LOW,  LOW, HIGH,  LOW}, /* 2 */
    { LOW,  LOW, HIGH, HIGH}, /* 3 */
    { LOW, HIGH,  LOW,  LOW}, /* 4 */
    { LOW, HIGH,  LOW, HIGH}, /* 5 */
    { LOW, HIGH, HIGH,  LOW}, /* 6 */
    { LOW, HIGH, HIGH, HIGH}, /* 7 */
    {HIGH,  LOW,  LOW,  LOW}, /* 8 */
    {HIGH,  LOW,  LOW, HIGH}, /* 9 */
  };
  
  digitalWrite(LedA, numbers[i%10].a);
  digitalWrite(LedB, numbers[i%10].b);
  digitalWrite(LedC, numbers[i%10].c);
  digitalWrite(LedD, numbers[i%10].d);

}
  void set_number2(const unsigned n) {
  static const struct number {
    uint8_t d;
    uint8_t c;
    uint8_t b;
    uint8_t a;
  } numbers[] = {
    { LOW,  LOW,  LOW,  LOW}, /* 0 */
    { LOW,  LOW,  LOW, HIGH}, /* 1 */
    { LOW,  LOW, HIGH,  LOW}, /* 2 */
    { LOW,  LOW, HIGH, HIGH}, /* 3 */
    { LOW, HIGH,  LOW,  LOW}, /* 4 */
    { LOW, HIGH,  LOW, HIGH}, /* 5 */
    { LOW, HIGH, HIGH,  LOW}, /* 6 */
    { LOW, HIGH, HIGH, HIGH}, /* 7 */
    {HIGH,  LOW,  LOW,  LOW}, /* 8 */
    {HIGH,  LOW,  LOW, HIGH}, /* 9 */
  };
  
  digitalWrite(LeA, numbers[n%10].a);
  digitalWrite(LeB, numbers[n%10].b);
  digitalWrite(LeC, numbers[n%10].c);
  digitalWrite(LeD, numbers[n%10].d);
    
  }

Thank you in advance Banned_L

Hi,

I can't see your diagram. Please post it according to the instructions in the forum guide.

Cd4511 cannot display "-" or "C", only "0" to "9". Must you use this chip?

i am sorry about that if i posted it in wrong forum but i didnt knew what is it programable question or multiplexing leds ... the diagram of my circuit is on the link to test run also to see what i mean i am in a wrong forum again i am sorry

its the only easy chip, that i have and i can find the table for the numbers.. ok i will make them fixed but is any chance to print correct values? in minus position thanks

Banned_L: i am sorry about that if i posted it in wrong forum but i didnt knew what is it programable question or multiplexing leds

You posted in the correct part of the forum. But you did not post your diagram correctly, because I cannot view it. If you read the forum guide, you will learn how to attach images to your post.

Banned_L: its the only easy chip, that i have and i can find the table for the numbers.. ok i will make them fixed but is any chance to print correct values? in minus position

It is not an easy chip, as you have already discovered. This chip is making your project more hard, not more easy. I would recommend using the chip MAX7219. The circuit will be much easier, the code will be much easier, and the display will look much better because it will be much brighter and you will be able to display your "-" and "C" as you wanted.

I tried the address you posted again earlier, and this time, after some delay, I was able to see the diagram.

Now that I have seen this, I can say even more clearly that MAX7219 will make your circuit and code so, so, so much simpler! Only one MAX chip will be needed for all 8 digits. Only one resistor, 2 capacitors and 3 Arduino pins will be required. You will not need any transistors.

Capture.PNG

PaulRB: I tried the address you posted again earlier, and this time, after some delay, I was able to see the diagram.

I am going to conclude you did that using a screenshot (OK: "Capture.jpg" :grinning: ) as the site specifically obfuscates the image itself.

Very/ typically obnoxious website! :roll_eyes:

PaulRB: ] I can say even more clearly that MAX7219 will make your circuit and code so, so, so much simpler! Only one MAX chip will be needed for all 8 digits. Only one resistor, 2 capacitors and 3 Arduino pins will be required. You will not need any transistors.

thank you very much this ic helped a lot you are awesome and again thanks for the tip