8X40 Led Matrix shift register

Hello, I would like your help to modify the code of my 8x40 led matrix. I would like to display a 5-digit number without scrolling. I use 5 shift registers 74HC595 for the columns and one for the rows, the code works fine but the scroll must disappear to show the complete number without movement its use is for a truck scale, I appreciate your help please

#define max_char 100
int charIndex;
int scrollspeed = 20; //Set the scroll speed ( lower=faster)
int i;
int x;
int y;
char r_char;

char msg[] = "53300"; //text here



//Columns
int clockPin1 = 2; //Arduino pin connected to Clock Pin 11 of 74HC595
int latchPin1 = 3; //Arduino pin connected to Latch Pin 12 of 74HC595
int dataPin1 = 4;  //Arduino pin connected to Data Pin 14 of 74HC595

//Rows
int clockPin2 = 5; //Arduino pin connected to Clock Pin 11 of 74HC595
int dataPin2 = 7;  //Arduino pin connected to Data Pin 14 of 74HC595

//BITMAP
//Bits in this array represents one LED of the matrix
// 8 is # of rows, 6 is # of LED matrices
byte bitmap[8][7]; 

int numZones = sizeof(bitmap) / 8; // One Zone refers to one 8 x 8 Matrix ( Group of 8 columns)
int maxZoneIndex = numZones - 1;
int numCols = numZones * 8;

char alphabets[][8] = {
  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // SPACE
  {0x00, 0x00, 0x00, 0x5F, 0x00, 0x00}, // !
  {0x00, 0x00, 0x07, 0x00, 0x07, 0x00}, // "
  {0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14}, // #
  {0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12}, // $
  {0x00, 0x23, 0x13, 0x08, 0x64, 0x62}, // %
  {0x00, 0x36, 0x49, 0x55, 0x22, 0x50}, // &
  {0x00, 0x00, 0x05, 0x03, 0x00, 0x00}, // '
  {0x00, 0x00, 0x1C, 0x22, 0x41, 0x00}, // (
  {0x00, 0x00, 0x41, 0x22, 0x1C, 0x00}, // )
  {0x00, 0x14, 0x08, 0x3E, 0x08, 0x14}, // *
  {0x00, 0x08, 0x08, 0x3E, 0x08, 0x08}, // +
  {0x00, 0x00, 0x50, 0x30, 0x00, 0x00}, // ,
  {0x00, 0x08, 0x08, 0x08, 0x08, 0x08}, // -
  {0x00, 0x00, 0x60, 0x60, 0x00, 0x00}, // .
  {0x00, 0x20, 0x10, 0x08, 0x04, 0x02}, // /

  {0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E}, // 0
  {0x00, 0x00, 0x42, 0x7F, 0x40, 0x00}, // 1
  {0x00, 0x42, 0x61, 0x51, 0x49, 0x46}, // 2
  {0x00, 0x21, 0x41, 0x45, 0x4B, 0x31}, // 3
  {0x00, 0x18, 0x14, 0x12, 0x7F, 0x10}, // 4
  {0x00, 0x27, 0x45, 0x45, 0x45, 0x39}, // 5
  {0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30}, // 6
  {0x00, 0x01, 0x71, 0x09, 0x05, 0x03}, // 7
  {0x00, 0x36, 0x49, 0x49, 0x49, 0x36}, // 8
  {0x00, 0x06, 0x49, 0x49, 0x29, 0x1E}, // 9

  {0x00, 0x36, 0x36, 0x00, 0x00, 0x00}, // :
  {0x00, 0x56, 0x36, 0x00, 0x00, 0x00}, // ;
  {0x00, 0x08, 0x14, 0x22, 0x41, 0x00}, // <
  {0x00, 0x14, 0x14, 0x14, 0x14, 0x14}, // =
  {0x00, 0x00, 0x41, 0x22, 0x14, 0x08}, // >
  {0x00, 0x02, 0x01, 0x51, 0x09, 0x06}, // ?
  {0x00, 0x30, 0x49, 0x79, 0x41, 0x3E}, // @

  {0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E}, // A
  {0x00, 0x7F, 0x49, 0x49, 0x49, 0x36}, // B
  {0x00, 0x3E, 0x41, 0x41, 0x41, 0x22}, // C
  {0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C}, // D
  {0x00, 0x7F, 0x49, 0x49, 0x49, 0x41}, // E
  {0x00, 0x7F, 0x09, 0x09, 0x09, 0x01}, // F
  {0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A}, // G
  {0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F}, // H
  {0x00, 0x00, 0x41, 0x7F, 0x41, 0x00}, // I
  {0x00, 0x20, 0x40, 0x41, 0x3F, 0x01}, // J
  {0x00, 0x7F, 0x08, 0x14, 0x22, 0x41}, // K
  {0x00, 0x7F, 0x40, 0x40, 0x40, 0x40}, // L
  {0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F}, // M
  {0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F}, // N
  {0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E}, // O
  {0x00, 0x7F, 0x09, 0x09, 0x09, 0x06}, // P
  {0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E}, // Q
  {0x00, 0x7F, 0x09, 0x19, 0x29, 0x46}, // R
  {0x00, 0x46, 0x49, 0x49, 0x49, 0x31}, // S
  {0x00, 0x01, 0x01, 0x7F, 0x01, 0x01}, // T
  {0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F}, // U
  {0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F}, // V
  {0x00, 0x3F, 0x40, 0x30, 0x40, 0x3F}, // W
  {0x00, 0x63, 0x14, 0x08, 0x14, 0x63}, // X
  {0x00, 0x07, 0x08, 0x70, 0x08, 0x07}, // Y
  {0x00, 0x61, 0x51, 0x49, 0x45, 0x43}, // Z

  {0x00, 0x00, 0x7F, 0x41, 0x41, 0x00}, // [
  {0x00, 0x02, 0x04, 0x08, 0x10, 0x20}, // backslash
  {0x00, 0x00, 0x41, 0x41, 0x7F, 0x00}, // ]
  {0x00, 0x04, 0x02, 0x01, 0x02, 0x04}, // ^
  {0x00, 0x40, 0x40, 0x40, 0x40, 0x40}, // _
  {0x00, 0x00, 0x01, 0x02, 0x04, 0x00}, // `

  {0x00, 0x20, 0x54, 0x54, 0x54, 0x78}, // a
  {0x00, 0x7F, 0x50, 0x48, 0x48, 0x30}, // b
  {0x00, 0x38, 0x44, 0x44, 0x44, 0x28}, // c
  {0x00, 0x38, 0x44, 0x44, 0x48, 0x7F}, // d
  {0x00, 0x38, 0x54, 0x54, 0x54, 0x18}, // e
  {0x00, 0x08, 0x7E, 0x09, 0x01, 0x02}, // f
  {0x00, 0x0C, 0x52, 0x52, 0x52, 0x3E}, // g
  {0x00, 0x7F, 0x08, 0x04, 0x04, 0x78}, // h
  {0x00, 0x00, 0x44, 0x7D, 0x40, 0x00}, // i
  {0x00, 0x20, 0x40, 0x44, 0x3D, 0x00}, // j
  {0x00, 0x7F, 0x10, 0x28, 0x44, 0x00}, // k
  {0x00, 0x00, 0x41, 0x7F, 0x40, 0x00}, // l
  {0x00, 0x78, 0x04, 0x18, 0x04, 0x78}, // m
  {0x00, 0x7C, 0x08, 0x04, 0x04, 0x78}, // n
  {0x00, 0x38, 0x44, 0x44, 0x44, 0x38}, // o
  {0x00, 0x7C, 0x14, 0x14, 0x14, 0x08}, // p
  {0x00, 0x08, 0x14, 0x14, 0x18, 0xFC}, // q
  {0x00, 0x7C, 0x08, 0x04, 0x04, 0x08}, // r
  {0x00, 0x48, 0x54, 0x54, 0x54, 0x20}, // s
  {0x00, 0x04, 0x3F, 0x44, 0x40, 0x20}, // t
  {0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C}, // u
  {0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C}, // v
  {0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C}, // w
  {0x00, 0x44, 0x28, 0x10, 0x28, 0x44}, // x
  {0x00, 0x0C, 0x50, 0x50, 0x50, 0x3C}, // y
  {0x00, 0x44, 0x64, 0x54, 0x4C, 0x44}, // z
  {0x00, 0x00, 0x08, 0x36, 0x41, 0x00}, // {
};

void clearBitmap()
{
  //Clear bitmap
  for (int row = 0; row < 8; row++) {
    for (int zone = 0; zone <= maxZoneIndex; zone++) {
      bitmap[row][zone] = 0;
    }
  }
}

void setup() {
  pinMode(latchPin1, OUTPUT);
  pinMode(clockPin1, OUTPUT);
  pinMode(dataPin1, OUTPUT);

  
  pinMode(clockPin2, OUTPUT);
  pinMode(dataPin2, OUTPUT);
  Serial.begin(9600);

  clearBitmap();
}

//FUNCTIONS
// Displays bitmap array in the matrix
void RefreshDisplay() {
  for (int row = 0; row < 8; row++) {
    int rowbit = 1 << row;
        shiftOut(dataPin2, clockPin2, LSBFIRST, rowbit);   //Transmit data

    //Start sending column bytes
    digitalWrite(latchPin1, LOW);//Hold latchPin LOW for transmitting data

    //Shift out to each matrix
    for (int zone = maxZoneIndex; zone >= 0; zone--)
    {
      shiftOut(dataPin1, clockPin1, MSBFIRST, bitmap[row][zone]);
    }

    //flip both latches at once to eliminate flicker
    digitalWrite(latchPin1, HIGH);//Return the latch pin 1 high to signal chip
   
    //Wait
    delayMicroseconds(300);
  }
}

// Converts row and colum to bitmap bit and turn it off/on
void Plot(int col, int row, bool isOn) {
  int zone = col / 8;
  int colBitIndex = x % 8;
  byte colBit = 1 << colBitIndex;
  if (isOn)
    bitmap[row][zone] =  bitmap[y][zone] | colBit;
  else
    bitmap[row][zone] =  bitmap[y][zone] & (~colBit);
}

// Plot each character of the message one column at a time, updated the display, shift bitmap left.
void XProcess() {
  for (charIndex = 0; charIndex < (sizeof(msg) - 1); charIndex++)
  {
    int alphabetIndex = msg[charIndex] - ' ';                                      // I changed '@' to ' ' to display the different alphabets
    if (alphabetIndex < 0) alphabetIndex = 0;

    //Draw one character of the message
    // Each character is 5 columns wide, loop two more times to create 2 pixel space betwen characters
    for (int col = 0; col < 8; col++)
    {
      for (int row = 0; row < 8; row++)
      {
        // Set the pixel to what the alphabet say for columns 0 thru 4, but always leave columns 5 and 6 blank.
        bool isOn = 0;
        if (col < 8) isOn = bitRead( alphabets[alphabetIndex][col], 7 - row ) == 1;
        Plot( numCols - 1, row, isOn); //Draw on the rightmost column, the shift loop below will scroll it leftward.
      }
      for (int refreshCount = 0; refreshCount < scrollspeed; refreshCount++)
        RefreshDisplay();
      //Shift the bitmap one column to left
      for (int row = 0; row < 8; row++)
      {
        for (int zone = 0; zone < numZones; zone++)
        {
          //This right shift would show as a left scroll on display because leftmost column is represented by least significant bit of the byte.
          bitmap[row][zone] = bitmap[row][zone] >> 1;
          // Shift over lowest bit from the next zone as highest bit of this zone.
          if (zone < maxZoneIndex) bitWrite(bitmap[row][zone], 7, bitRead(bitmap[row][zone + 1], 0));
        }
      }
    }
  }
}

void serialInput() {
  //check if serial is avaible an before reading a new message delete's the old message
  if (Serial.available()) {
    for (i = 0; i < 105; i++) {
      msg[i] = '\0';
    }
    //resests the index
    charIndex = 0;
  }
  //while is reading the message
  while (Serial.available()) {
    //the message can have up to 100 characters
    if (charIndex < (max_char - 1))
    {
      r_char = Serial.read();      // Reads a character
      msg[charIndex] = r_char;     // Stores the character in message array
      charIndex++;                     // Increment position
      msg[charIndex] = '\0';       // Delete the last position
    }
  }
}
void loop() {
  XProcess();
  serialInput();
}

Suggest you look at using MAX7219/7221, 100 times easier :wink: .

IMG_1985


Data sheet:


About $15.00

2 Likes
char msg[6] = "53300"; //text here

//Columns
const byte ColClockPin = 2; //Arduino pin connected to Clock Pin 11 of 74HC595
const byte LatchPin = 3; //Arduino pin connected to Latch Pin 12 of 74HC595 of both column and row
const byte ColDataPin = 4;  //Arduino pin connected to Data Pin 14 of 74HC595

//Rows
const byte RowClockPin = 5; //Arduino pin connected to Clock Pin 11 of 74HC595
const byte RowDataPin = 7;  //Arduino pin connected to Data Pin 14 of 74HC595

const byte  numZones = 5; // One Zone refers to one 8 x 8 Matrix ( Group of 8 columns)


char alphabets[10][7] = {
  {0x0E, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0E},// 0
  {0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08},
  {0x0E, 0x11, 0x01, 0x06, 0x08, 0x10, 0x1F},
  {0x1E, 0x01, 0x01, 0x0E, 0x01, 0x01, 0x1E},
  {0x11, 0x11, 0x11, 0x1F, 0x01, 0x01, 0x01},
  {0x1F, 0x10, 0x10, 0x1E, 0x01, 0x01, 0x1E},
  {0x0F, 0x10, 0x10, 0x0E, 0x11, 0x11, 0x0E},
  {0x1F, 0x01, 0x01, 0x06, 0x08, 0x08, 0x08},
  {0x0E, 0x11, 0x11, 0x0E, 0x11, 0x11, 0x0E},
  {0x0E, 0x11, 0x11, 0x0F, 0x01, 0x01, 0x0E} // 9
};

void setup() {
  pinMode(LatchPin, OUTPUT);
  pinMode(ColClockPin, OUTPUT);
  pinMode(ColDataPin, OUTPUT);
  pinMode(RowClockPin, OUTPUT);
  pinMode(RowDataPin, OUTPUT);
  Serial.begin(115200);
  //XProcess();
}



void loop() {
  if (Serial.available() > 0) {
    byte charIndex = 0;

    while (Serial.available() > 0) {
      char r_char = Serial.read();      // Reads a character
      if (r_char >= '0' && r_char <= '9' && charIndex < 5) {
        msg[charIndex] = r_char;     // Stores the character in message array
        charIndex++;                     // Increment position
      }
      else while (Serial.available() > 0)Serial.read();
    }

    for (byte row = 0; row < 7; row++) {
      digitalWrite(LatchPin, LOW);//Hold latchPin LOW for transmitting data
      byte rowbit = 1 << (row + 1);
      shiftOut(RowDataPin, RowClockPin, LSBFIRST, rowbit);   //Transmit data
      for (byte zone = 0; zone < charIndex; zone--)shiftOut(ColDataPin, ColClockPin, MSBFIRST, alphabets[msg[zone] - '0'][row]);
      digitalWrite(LatchPin, HIGH);//Return the latch pin 1 high to signal chip   //flip both latches at once to eliminate flicker
      delayMicroseconds(300);
    }
  }
}

Hello Kolaha, i test it but not works only get leds strobe

did you send over serial some number?

yes and I got the same thing, random blinks in the leds

Make sure you add a decoupling capacitor to each I.C.

ah, yes, of course, hier:

char msg[6] = "53300"; //text here

//Columns
const byte ColClockPin = 2; //Arduino pin connected to Clock Pin 11 of 74HC595
const byte LatchPin = 3; //Arduino pin connected to Latch Pin 12 of 74HC595 of both column and row
const byte ColDataPin = 4;  //Arduino pin connected to Data Pin 14 of 74HC595

//Rows
const byte RowClockPin = 5; //Arduino pin connected to Clock Pin 11 of 74HC595
const byte RowDataPin = 7;  //Arduino pin connected to Data Pin 14 of 74HC595

const byte  numZones = 5; // One Zone refers to one 8 x 8 Matrix ( Group of 8 columns)


char alphabets[10][7] = {
  {0x0E, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0E},// 0
  {0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08},
  {0x0E, 0x11, 0x01, 0x06, 0x08, 0x10, 0x1F},
  {0x1E, 0x01, 0x01, 0x0E, 0x01, 0x01, 0x1E},
  {0x11, 0x11, 0x11, 0x1F, 0x01, 0x01, 0x01},
  {0x1F, 0x10, 0x10, 0x1E, 0x01, 0x01, 0x1E},
  {0x0F, 0x10, 0x10, 0x0E, 0x11, 0x11, 0x0E},
  {0x1F, 0x01, 0x01, 0x06, 0x08, 0x08, 0x08},
  {0x0E, 0x11, 0x11, 0x0E, 0x11, 0x11, 0x0E},
  {0x0E, 0x11, 0x11, 0x0F, 0x01, 0x01, 0x0E} // 9
};

void setup() {
  pinMode(LatchPin, OUTPUT);
  pinMode(ColClockPin, OUTPUT);
  pinMode(ColDataPin, OUTPUT);
  pinMode(RowClockPin, OUTPUT);
  pinMode(RowDataPin, OUTPUT);
  Serial.begin(115200);
}



void loop() {
  for (byte row = 0; row < 7; row++) {
    digitalWrite(LatchPin, LOW);//Hold latchPin LOW for transmitting data
    byte rowbit = 1 << (row + 1);
    shiftOut(RowDataPin, RowClockPin, LSBFIRST, rowbit);   //Transmit data
    for (byte zone = 0; zone < 5; zone--)shiftOut(ColDataPin, ColClockPin, MSBFIRST, (msg[zone]) ? alphabets[msg[zone] - '0'][row] : 0);
    digitalWrite(LatchPin, HIGH);//Return the latch pin 1 high to signal chip   //flip both latches at once to eliminate flicker
    delayMicroseconds(300);
  }
  if (Serial.available() > 0) {
    byte charIndex = 0;

    while (Serial.available() > 0) {
      char r_char = Serial.read();      // Reads a character
      if (r_char >= '0' && r_char <= '9' && charIndex < 5) {
        msg[charIndex] = r_char;     // Stores the character in message array
        charIndex++;                     // Increment position
      }
      else while (Serial.available() > 0)Serial.read();
    }
    if (charIndex < 5)for (byte zone = 5; zone > 0; zone--)msg[zone - 1] = (zone > 5 - charIndex) ? msg[zone + charIndex - 1 - 5] : 0;
  }
}

works better but only get the first digit which is scrolled up in each matrix

  for (byte row = 0; row < 8; row++) {
    digitalWrite(LatchPin, LOW);//Hold latchPin LOW for transmitting data
    byte rowbit = 1 << row ;
    shiftOut(RowDataPin, RowClockPin, LSBFIRST, rowbit);   //Transmit data
    for (byte zone = 0; zone < 5; zone--)shiftOut(ColDataPin, ColClockPin, MSBFIRST, (msg[zone]) ? alphabets[msg[zone] - '0'][row] : 0);
    shiftOut(ColDataPin, ColClockPin, MSBFIRST,  0);
    digitalWrite(LatchPin, HIGH);//Return the latch pin 1 high to signal chip   //flip both latches at once to eliminate flicker
    delayMicroseconds(300);
  }

hello, not work :frowning:

Each successive character is offset by one more row.

Show the output.

Hello, I share the final solution, thank you all.

char msg[6] = ""; //text here

//Columns
const byte ColClockPin = 2; //Arduino pin connected to Clock Pin 11 of 74HC595
const byte LatchPin = 3; //Arduino pin connected to Latch Pin 12 of 74HC595 of both column and row
const byte ColDataPin = 4;  //Arduino pin connected to Data Pin 14 of 74HC595

//Rows
const byte RowClockPin = 5; //Arduino pin connected to Clock Pin 11 of 74HC595
const byte RowDataPin = 7;  //Arduino pin connected to Data Pin 14 of 74HC595

const byte  numZones = 5; // One Zone refers to one 8 x 8 Matrix ( Group of 8 columns)


char alphabets[10][7] = {
  {0x0E, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0E},// 0
  {0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08},
  {0x0E, 0x11, 0x01, 0x06, 0x08, 0x10, 0x1F},
  {0x1E, 0x01, 0x01, 0x0E, 0x01, 0x01, 0x1E},
  {0x11, 0x11, 0x11, 0x1F, 0x01, 0x01, 0x01},
  {0x1F, 0x10, 0x10, 0x1E, 0x01, 0x01, 0x1E},
  {0x0F, 0x10, 0x10, 0x0E, 0x11, 0x11, 0x0E},
  {0x1F, 0x01, 0x01, 0x06, 0x08, 0x08, 0x08},
  {0x0E, 0x11, 0x11, 0x0E, 0x11, 0x11, 0x0E},
  {0x0E, 0x11, 0x11, 0x0F, 0x01, 0x01, 0x0E} // 9
};

void setup() {
  pinMode(LatchPin, OUTPUT);
  pinMode(ColClockPin, OUTPUT);
  pinMode(ColDataPin, OUTPUT);
  pinMode(RowClockPin, OUTPUT);
  pinMode(RowDataPin, OUTPUT);
  Serial.begin(115200);
}



void loop() {
  for (byte row = 0; row < 7; row++) {
    digitalWrite(LatchPin, LOW);//Hold latchPin LOW for transmitting data
    byte rowbit = 1 << (row + 1);
    shiftOut(RowDataPin, RowClockPin, LSBFIRST, rowbit);   //Transmit data
    for (byte zone = 0; zone < 5; zone++)shiftOut(ColDataPin, ColClockPin, MSBFIRST, (msg[zone]) ? alphabets[msg[zone] - '0'][row] : 0);
    digitalWrite(LatchPin, HIGH);//Return the latch pin 1 high to signal chip   //flip both latches at once to eliminate flicker
    delayMicroseconds(300);
  }
  if (Serial.available() > 0) {
    byte charIndex = 0;

    while (Serial.available() > 0) {
      char r_char = Serial.read();      // Reads a character
      if (r_char >= '0' && r_char <= '9' && charIndex < 5) {
        msg[charIndex] = r_char;     // Stores the character in message array
        charIndex++;                     // Increment position
      }
      else while (Serial.available() > 0)Serial.read();
    }
    if (charIndex < 5)for (byte zone = 5; zone > 0; zone--)msg[zone - 1] = (zone > 5 - charIndex) ? msg[zone + charIndex - 1 - 5] : 0;
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.