Go Down

Topic: Having trouble controlling 3 Row Seven Segment with 4 shift register 74hc595 (Read 2102 times) previous topic - next topic

zifank

yes, the vendor make me crazy !!!,,,

I think, I had to wait for 2 weeks for the answer.


thanks PaulRB for u support...

PaulRB

Anyway, you have not yet explained what happens when you run that code I have you.

zifank


PaulRB

You don't use code tags to post links, you use link tags, like this. Did you read the forum guidelines yet? Please do that.

And why have you not posted that schematic? You only do half the things that I ask!


Try this
Code: [Select]

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column+1)); // send the column enable mask
    for (byte row = 0; row < 3; row++) // update each row for the current column
    {
      byte d = displayBuffer[row][column]; // get the required digit for this row & column
      shiftOut(dataPin, clockPin, MSBFIRST, digit[d]); // send the segment data for each row
    }
    digitalWrite(latchPin, HIGH);

zifank

paulRB, this is second result.


Code: [Select]
int latchPin = 4;
int clockPin = 3;
int dataPin = 2;

// digits from the right
const byte digit[10] =      //seven segment digits in bits
{
  B10000001,  // 0
  B11110011,  // 1
  B01001001,  // 2
  B01100001,  // 3
  B00110011,  // 4
  B00100101,  // 5
  B00000101,  // 6
  B11110001,  // 7
  B00000001,  // 8  fix
  B00100001,  // 9
};

byte displayBuffer[3][6] =    //digit to display in each position
{
  {0, 1, 2, 3, 4, 5},
  {0, 1, 2, 3, 4, 5},
  {0, 1, 2, 3, 4, 9}
};



void setup()
{
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
 
}

void loop()
{
 
  updateShiftRegister();

}

void sevoff() {
  static byte column; // the column currently being lit
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column + 5)); // send the column enable mask
  for (byte row = 0; row < 3; row++) // update each row for the current column
  {
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000);// send the segment data for each row

  }
  digitalWrite(latchPin, HIGH);
}

void test() {
  static byte column; // the column currently being lit
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column + 0)); // send the column enable mask
  shiftOut(dataPin, clockPin, MSBFIRST, digit[1]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[1]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[1]);
  digitalWrite(latchPin, HIGH);
  delay(1000);
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column + 1)); // send the column enable mask
  shiftOut(dataPin, clockPin, MSBFIRST, digit[2]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[2]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[2]);
  digitalWrite(latchPin, HIGH);
  delay(1000);
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column + 2)); // send the column enable mask
  shiftOut(dataPin, clockPin, MSBFIRST, digit[3]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[3]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[3]);
  digitalWrite(latchPin, HIGH);
  delay(1000);
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column + 3)); // send the column enable mask
  shiftOut(dataPin, clockPin, MSBFIRST, digit[4]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[4]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[4]);
  digitalWrite(latchPin, HIGH);
  delay(1000);
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column + 4)); // send the column enable mask
  shiftOut(dataPin, clockPin, MSBFIRST, digit[5]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[5]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[5]);
  digitalWrite(latchPin, HIGH);
  delay(1000);
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column + 5)); // send the column enable mask
  shiftOut(dataPin, clockPin, MSBFIRST, digit[6]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[6]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[6]);
  digitalWrite(latchPin, HIGH);
}



void updateShiftRegister()
{
  // "static" variables do not loose their value when the function ends
  static unsigned long lastUpdateTime; // time from millis() when the dispaly was last updated
  static byte column; // the column currently being lit

  if (millis() - lastUpdateTime > 3)  // is it time to light the next column?
  {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column+1)); // send the column enable mask
    for (byte row = 0; row < 3; row++) // update each row for the current column
    {
      byte d = displayBuffer[row][column]; // get the required digit for this row & column
      shiftOut(dataPin, clockPin, MSBFIRST, digit[d]); // send the segment data for each row
    }
    digitalWrite(latchPin, HIGH);

    column++; // next time, we will light the next column
    if (column > 5) column = 0;
    lastUpdateTime = millis();
    delay(1000);
  }
}



video
https://youtu.be/4UjsA-2mpME

PaulRB

Interesting, but not what I wanted to see. I wanted to see if the code I gave you worked. That video shows the code you added running. I can see why your code does not light the leftmost digit.

zifank

Interesting, but not what I wanted to see. I wanted to see if the code I gave you worked. That video shows the code you added running. I can see why your code does not light the leftmost digit.
agree, your code almost right.
the light can't show the leftmost digit, how can i solved this?

maybe can you show me the code if the case is:

Row 1 (top, with 6 digits) show number "123.456"
Row 2 (middle with 4 digit) show "78.90"
Row 3 (bottom, with 5 digit) show "12.456"

thanks PaulRB, you are the Real Master..




PaulRB

Did you make the change I suggested in post #33? I hoped that would fix the leftmost digit.

If you take my code from post #25 and add the changes from post #33, what digits do you see displayed?

zifank

Did you make the change I suggested in post #33? I hoped that would fix the leftmost digit.

If you take my code from post #25 and add the changes from post #33, what digits do you see displayed?
I've changed the code in the post #25,
and add the code in the post #33. the result is like in the video above, the display show a number from Array of displayBuffer are vertical not of horizontal.


zifank

paulRb, one more question of new case,

how to hold the first number in first digit, and the second digit show a second number, i've a trouble to keep first digit. show only a second digit from two number. can u give me simple code to keep/hold that first number in first digit?

or

maybe can you show me the code if the case is:

Row 1 (top, with 6 digits) show number "123.456"
Row 2 (middle with 4 digit) show "78.90"
Row 3 (bottom, with 5 digit) show "12.456"

I'm trying to learn the code.

PaulRB

I've changed the code in the post #25,
and add the code in the post #33. the result is like in the video above
No, it is not. I am not stupid. I can see that the video is not my code running. It is your code running. I said that in post #35. I asked you to describe what happens when you run my code. Until you do as I ask, I will give you no more help.

zifank

sorry paul, Why should I lie to you?

Code: [Select]
int latchPin = 4;
int clockPin = 3;
int dataPin = 2;

// digits from the right
const byte digit[10] =      //seven segment digits in bits
{
  B10000001,  // 0
  B11110011,  // 1
  B01001001,  // 2
  B01100001,  // 3
  B00110011,  // 4
  B00100101,  // 5
  B00000101,  // 6
  B11110001,  // 7
  B00000001,  // 8  fix
  B00100001,  // 9
};

byte displayBuffer[3][6] =    //digit to display in each position
{
  {0, 1, 2, 3, 4, 5},
  {0, 1, 2, 3, 4, 5},
 {0, 1, 2, 3, 4, 5},
};



void setup()
{
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
 
}

void loop()
{
 
  updateShiftRegister();

}

void sevoff() {
  static byte column; // the column currently being lit
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column + 5)); // send the column enable mask
  for (byte row = 0; row < 3; row++) // update each row for the current column
  {
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000);// send the segment data for each row

  }
  digitalWrite(latchPin, HIGH);
}


void updateShiftRegister()
{
  // "static" variables do not loose their value when the function ends
  static unsigned long lastUpdateTime; // time from millis() when the dispaly was last updated
  static byte column; // the column currently being lit

  if (millis() - lastUpdateTime > 3)  // is it time to light the next column?
  {
    // form code post#25
    //digitalWrite(latchPin, LOW);
    //for (byte row = 0; row < 3; row++) // update each row for the current column
    //{
      //byte d = displayBuffer[row][column]; // get the required digit for this row & column
      //shiftOut(dataPin, clockPin, MSBFIRST, digit[d]); // send the segment data for each row
    //}
    //shiftOut(dataPin, clockPin, MSBFIRST, 1 << column); // send the column enable mask
    //digitalWrite(latchPin, HIGH);
    //end code post #25

    //from code post #33
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column+1)); // send the column enable mask
    for (byte row = 0; row < 3; row++) // update each row for the current column
    {
      byte d = displayBuffer[row][column]; // get the required digit for this row & column
      shiftOut(dataPin, clockPin, MSBFIRST, digit[d]); // send the segment data for each row
    }
    digitalWrite(latchPin, HIGH);
    //end code post #3
    delay(1000);

    column++; // next time, we will light the next column
    if (column > 5) column = 0;
    lastUpdateTime = millis();
  }
}


 


video test 3
https://youtu.be/f23rSsLLO0E?
   

PaulRB

Ok.

Change this line:
Code: [Select]

    shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column+2)); // send the column enable mask

zifank

this is the test 5, i changed from post#42


Code: [Select]
int latchPin = 4;
int clockPin = 3;
int dataPin = 2;

// digits from the right
const byte digit[10] =      //seven segment digits in bits
{
  B10000001,  // 0
  B11110011,  // 1
  B01001001,  // 2
  B01100001,  // 3
  B00110011,  // 4
  B00100101,  // 5
  B00000101,  // 6
  B11110001,  // 7
  B00000001,  // 8  fix
  B00100001,  // 9
};

byte displayBuffer[3][6] =    //digit to display in each position
{
  {1, 1, 1, 1, 1, 1},
  {2, 2, 2, 2, 2, 2},
  {3, 3, 3, 3, 3, 3},
};



void setup()
{
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);


}

void loop()
{
  updateShiftRegister();
}


void updateShiftRegister()
{
  // "static" variables do not loose their value when the function ends
  static unsigned long lastUpdateTime; // time from millis() when the dispaly was last updated
  static byte column; // the column currently being lit

  if (millis() - lastUpdateTime > 3)  // is it time to light the next column?
  {
    //from code post #33
    digitalWrite(latchPin, LOW);
    //from code post #42
    shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column+2)); // send the column enable mask //coloum
    for (byte row = 0; row < 3; row++) // update each row for the current column
    {
      byte d = displayBuffer[row][column]; // get the required digit for this row & column
      shiftOut(dataPin, clockPin, MSBFIRST, digit[d]); // send the segment data for each row
    }
    digitalWrite(latchPin, HIGH);
    //end code post #33

    column++; // next time, we will light the next column
    if (column > 6) column = 0;
    lastUpdateTime = millis();
  }
}




the video result is
https://youtu.be/i5ftj0wx1Pg




PaulRB

You changed this line:
Code: [Select]

    if (column > 6) column = 0;

but I do not think correcting that will fix the display.

Did you make other changes that I have not detected?

Go Up