Pages: [1]   Go Down
Author Topic: Need some help with my 7 Segment Display  (Read 701 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, i have a 2 digit 7 segment display which is common anode. I am using the code and circuit diagram from here http://www.sweeting.org/mark/blog/2011/11/27/arduino-74hc595-shift-register-and-a-7-segment-led-display. However i have modified the code slightly as follows :

Code:
const int latchPin = 5;  // Pin connected to Pin 12 of 74HC595 (Latch)
const int dataPin  = 6;  // Pin connected to Pin 14 of 74HC595 (Data)
const int clockPin = 7;  // Pin connected to Pin 11 of 74HC595 (Clock)

unsigned long t1;
unsigned long t2;
int i = 0;

int swch = 0;

// Describe each digit in terms of display segments
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
const byte numbers[10] = {
  0b11111100,
  0b01100000,
  0b11011010,
  0b11110010,
  0b01100110,
  0b10110110,
  0b10111110,
  0b11100000,
  0b11111110,
  0b11100110
};

void setup()
{

  // initialisation time
  t1 = millis();

  //set pins to output
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  pinMode(2, OUTPUT); //Connects to right character common anode
  pinMode(3, OUTPUT); //Connects to left character common anode

}

void loop()
{
  if(swch==0)
  {
    digitalWrite(3, LOW);
    digitalWrite(2, HIGH);

    show(numbers[1]);
    swch=1;
  }
  else
  {
    swch=0;

    digitalWrite(3, HIGH);
    digitalWrite(2, LOW);
    show(numbers[2]);
  }


}

void show( byte number)
{
  // Use a loop and a bitwise AND to move over each bit that makes up
  // the seven segment display (from left to right, A => G), and check
  // to see if it should be on or not
  for(int j = 0; j <= 7; j++)
  {
    delay(1);
    byte toWrite = number & (0b10000000 >> j);

    // If all bits are 0 then no point writing it to the shift register,
    // so break out and move on to next segment.
    if(!toWrite) {
      continue;
    }

    // Otherwise shift it into the register
    shiftIt(toWrite);
  }
}

void shiftIt (byte data)
{
  // Set latchPin LOW while clocking these 8 bits in to the register
  digitalWrite(latchPin, LOW);

  for (int k=0; k <= 7; k++)
  {
    // clockPin LOW prior to sending a bit
    digitalWrite(clockPin, LOW);

    // Note that in our case, we need to set pinState to 0 (LOW) for
    // “On” as the 74HC595 is sinking current when using a common
    // anode display. If you want to use a common cathode display then
    // switch this around.
    if ( data & (1 << k) )
    {
      digitalWrite(dataPin, LOW); // turn “On”
    }
    else
    {
      digitalWrite(dataPin, HIGH); // turn “Off”
    }

    // and clock the bit in
    digitalWrite(clockPin, HIGH);
  }

  //stop shifting out data
  digitalWrite(clockPin, LOW);

  //set latchPin to high to lock and send data
  digitalWrite(latchPin, HIGH);


  // put delay here if you want to see the multiplexing in action!
  //delay(1000);
}


The problem is that when displaying a one the numbers blur together so if trying to display 21 it looks like this  (appologies for the terrible art)

----       
    |          |
----      ----
|   |          |
----   

Upon slowing it down what happens is that when it switches from lighting the one to lighting the two one of the LEDS briefly flashes on in this case the bottom right LED. Does anyone know how i can fix this or is what i am doing a bad way of doing things?

Thanks for your help.
Logged

Denmark
Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.
 
Hmm... Are you only using one shift for two displays?

How have you done the wiring? picture?
Logged

Pages: [1]   Go Up
Jump to: