help me coding for 2 digit 7 segment

I have connected two 7 Segment display in parallel and have connected them to the outputs of the arduino
but have fed the common with two different outputs of arduino

now I want it to display 00 - 99
but there will be very quick shifts between the commons of the 7 segment

I have attached the diagram below...

please give me ideas to write the code...

I want to drive the displays in this way..[/b]

You're going to need to refresh the leds constantly otherwise the leds will fade quickly. To do this in the Arduino, best write an interrupt function to refresh in the background. Your display function will then only write the pattern to display into a variable which will be updated in the next cycle.

If that's too complicated, you're going to need some kind of latch chip. But if you wanted that, getting a serial LED driver or a 74HC595 would be preferable.

If I get round to it, I might take a look at this. That sounds fun.

Korman

I have attached the diagram below..

the problem with that is that you are asking the arduino to supply too much current through the pins 11 & 12. This is handled by transistors in your lower diagram.
Are you aware that 7 seg displays come in two types, common anode and common cathode. The type used in the bottom circuit is a common cathode, is this the type you have?

Hi,

Your original design just needs the transistor part of your second schematic adding to pins 11 and 12, or as Mike says, you will be asking the pins to sink 8 times the current through each LED segment which adds up to too much.

There is a simple example of a 2 digit 7 segment display drive in my book.

Here is the code:

// Project 14 - Double Dice

int segmentPins[] = {3, 2, 19, 16, 18, 4, 5, 17}; 
int displayPins[] = {10, 11};

int buttonPin = 12;

byte digits[10][8] = {
//  a  b  c  d  e  f  g  .
  { 1, 1, 1, 1, 1, 1, 0, 0},  // 0
  { 0, 1, 1, 0, 0, 0, 0, 0},  // 1
  { 1, 1, 0, 1, 1, 0, 1, 0},  // 2
  { 1, 1, 1, 1, 0, 0, 1, 0},  // 3
  { 0, 1, 1, 0, 0, 1, 1, 0},  // 4
  { 1, 0, 1, 1, 0, 1, 1, 0},  // 5
  { 1, 0, 1, 1, 1, 1, 1, 0},  // 6
  { 1, 1, 1, 0, 0, 0, 0, 0},  // 7
  { 1, 1, 1, 1, 1, 1, 1, 0},  // 8  
  { 1, 1, 1, 1, 0, 1, 1, 0}  // 9  
};
   
void setup()
{
  for (int i=0; i < 8; i++)
  {
    pinMode(segmentPins[i], OUTPUT);
  }
  pinMode(displayPins[0], OUTPUT);
  pinMode(displayPins[1], OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop()
{
  static int dice1;
  static int dice2;
  if (digitalRead(buttonPin))
  {
    dice1 = random(1,7);
    dice2 = random(1,7);
  }
  updateDisplay(dice1, dice2);
}

void updateDisplay(int value1, int value2)
{
  digitalWrite(displayPins[0], LOW);
  digitalWrite(displayPins[1], HIGH);
  setSegments(value1);
  delay(5);
  digitalWrite(displayPins[0], HIGH);
  digitalWrite(displayPins[1], LOW);
  setSegments(value2);
  delay(5);  
}

void setSegments(int n)
{
  for (int i=0; i < 8; i++)
  {
    digitalWrite(segmentPins[i], ! digits[n][i]);
  } 
}
1 Like