Digit Counter with 7-segment LED + Arduino

It just counts 0 to 9 with 7-segment LED. Only digit 1 side has been used since the digit 2 is burned out…
Adjust output pins for your environment. For simplicity, you need 7 pins for output in this example.
I am sure I can reduce the number of pins with demux. That’s gonna be the next project.

Parts: Arduino Duemilanove, Breadboard, a register and LTD-5523AB (Datasheet)

The LED-facing-upright LTD-5523AB pin-order is:

18, 17, 16, 15, 14, 13, 12, 11, 10pin 
[------------LTD-5523AB------------] | - A - | | - A - | F B F B | - G - | | - G - | E C E C | - D - | | - D - | [------------LTD-5523AB------------] 01, 02, 03, 04, 05, 06, 07, 08, 09pin

[7-segment LED for digit 1]
A = 16pin, B = 15pin, C = 03pin, D = 02pin, E = 01pin, F = 18pin, DP = 04pin
14pin is common cathode for digit 1 (it means it should be GNDed all the time.)

For example, to make the digit 3, just turn on A, B, C, D and G.

[7segment.pde]
//Output Pins
//* Adjust this for your pin outputs.
int ledPin[8] = {4, 5, 6, 7, 9, 10, 11, 12};  

//Segment to Pin
//* Adjust this for your 7 segment LED spec.
//                 A,  B, C, D, E,  F,  G, DP
int Seg2Pin[8] = {11, 10, 5, 6, 7, 9, 12, 4};

//Digit to Segment
// * You don't need modify this unless you want to change digits.
int Dec2Seg[11] = 
{
//A(125), B(64), C(32), D(16), E(8), F(4), G(2), DP(1)
  0x07E, //Digit 0
  0x00C, //Digit 1
  0x0B6, //Digit 2
  0x09E, //Digit 3
  0x0CC, //Digit 4
  0x0DA, //Digit 5
  0x0FB, //Digit 6
  0x00E, //Digit 7
  0x0FF, //Digit 8  
  0x0DF, //Digit 9  
  0x100 //DP
};

void setup()                    // run once, when the sketch starts
{
  for (int i = 0; i < 8; i++)
    pinMode(ledPin[i], OUTPUT);      // sets the digital pin as output
}

void clearAllSegments()
{
  //Turn off all segments
  for (int i = 0; i  0)
  {
    seg /= 2;    
    if (seg & 0x1)
      digitalWrite(Seg2Pin[pin], HIGH);   // sets the LED on    
    pin++;
  }
}

void loop()                     // run over and over again
{
  //Count 0 to 9
  for( int digit = 0; digit <= 10; digit++)
  {    
    drawDigit(digit);    
    delay(1000);                  // waits for a second
    clearAllSegments();    
  }
}

Update 1: I change the 13pin to 9pin for output since 13pin has some builtin register.
Update 2: I implemented a bit mask to select segments.n

Advertisements

3 Responses to “Digit Counter with 7-segment LED + Arduino”

  1. Dids Says:

    The code you’ve supplied in this post doesn’t seem to work. For example, drawDigit’s not been initialized anywhere?

  2. genki Says:

    I believe WordPress jumbled around my code…
    I don’t have any backup for this code, but it should be like this below. Let me know if it still doesn’t work. Now I know how to drive 4-digit 7-segment LED with shift register.

    void drawDigit(int dec)
    {
    int seg = Dec2Seg[dec];

    for (int pin = 0; pin < 8; pin++)
    {
    seg /= 2;
    if (seg & 0x1)
    digitalWrite(Seg2Pin[pin], HIGH); // sets the LED on
    }
    }

    void clearAllSegments()
    {
    for (int pin = 0; pin < 8; pin++)
    {
    digitalWrite(Seg2Pin[pin], LOW);
    }
    }

  3. saw0 Says:

    The Second Digit will burn out as fast, if you dont add resistors…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: