5x8 Addressable LED display

VK3ZYZ

Moderator
Staff member
Josh sent me a neat little display.
It is about 13x19mm and has 40 RGB LEDs on it in a 5 x 8 matrix. Each LED is addressable for colour and brightness.
Photo on 24-10-2023 at 12.04 PM.jpg

It is hard to get a good picture.
 

VK3ZYZ

Moderator
Staff member
This works, but it needs a couple of displays.
Code:
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>

// MATRIX DECLARATION:
// Parameter 1 = width of NeoPixel matrix
// Parameter 2 = height of matrix
// Parameter 3 = pin number (most are valid)
// Parameter 4 = matrix layout flags, add together as needed:
//   NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
//     Position of the FIRST LED in the matrix; pick two, e.g.
//     NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
//   NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
//     rows or in vertical columns, respectively; pick one or the other.
//   NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
//     in the same order, or alternate lines reverse direction; pick one.
//   See example below for these values in action.
// Parameter 5 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)

int matrixW = 8;
int matrixH = 5;
#define PIN 5 // OUTPUT PIN FROM ARDUINO TO MATRIX D-In

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(matrixW, matrixH, PIN,
//                            NEO_MATRIX_TOP     + NEO_MATRIX_LEFT +
                            NEO_MATRIX_TOP     + NEO_MATRIX_RIGHT +
                            NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
                            NEO_GRB            + NEO_KHZ800);

const uint16_t colors[] = {
  matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(255, 255, 0), matrix.Color(0, 0, 255), matrix.Color(255, 0, 255), matrix.Color(0, 255, 255), matrix.Color(255, 255, 255)
};

#define arr_len( x )  ( sizeof( x ) / sizeof( *x ) ) // Calculation of Array Size;

int pixelPerChar = 6; // Width of Standard Font Characters is 8X6 Pixels
int x = matrix.width(); // Width of the Display
int pass = 0; // Counter
int i = 0; // Counter
int clr = 0; // Counter for Indexing Array of Colors

char msg[] = "-------------------"; // BLANK Message of Your Choice;

void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(5);
  matrix.setTextColor(colors[0]);
}

void loop() {
  int arrSize = arr_len( colors );
  char exampleText[] = "Hello Josh"; // SCROLLING Message of Your Choice;
  writeText(exampleText);
  delay(1000);

  matrix.print(msg); //Print the Message String;
  matrix.show();
  delay(1000);

  /*  Commands for Debugging  */
  char msgText[] = "It works :)";
  matrix.print(msgText); // Scrolling Print the Message String;
  matrix.show();
  delay(1000);
  
  writeText("End of Loop"); //Print the Message String;
  delay(1000);
  /*  Commands for Debugging  */
  
  // LATHER - RINSE - REPEAT Is Why coders never leave the Shower;
}

/* --------------------  FUNCTIONS BELOW  --------------------  */
void writeText(String msg) {
  int arrSize = arr_len( colors ); // Array of Text Colors;
  int msgSize = (msg.length() * pixelPerChar) + (2 * pixelPerChar); // CACULATE message length;
  int scrollingMax = (msgSize) + matrix.width(); // ADJUST Displacement for message length;

  x = matrix.width(); // RESET Cursor Position and Start Text String at New Position on the Far Right;
  clr = 0; // RESET Color/Repeat Index;

  while (clr <= arrSize) {
    /* Change Color with Each Pass of Complete Message */
    matrix.setTextColor(colors[clr]);

    matrix.fillScreen(0); // BLANK the Entire Screen;
    matrix.setCursor(x, 0); // Set Starting Point for Text String;
    matrix.print(msg); // Set the Message String;

    /* SCROLL TEXT FROM RIGHT TO LEFT BY MOVING THE CURSOR POSITION */
    if (--x < -scrollingMax ) {

      /*  ADJUST FOR MESSAGE LENGTH  */
      // Decrement x by One AND Compare New Value of x to -scrollingMax;
    // This Animates (moves) the text by one pixel to the Left;

      x = matrix.width(); // After Scrolling by scrollingMax pixels, RESET Cursor Position and Start String at New Position on the Far Right;
     

      ++clr; // INCREMENT COLOR/REPEAT LOOP COUNTER AFTER MESSAGE COMPLETED;
    }
    matrix.show(); // DISPLAY the Text/Image
    delay(40); // SPEED OF SCROLLING or FRAME RATE;
  }
  clr = 0; // Reset Color/Loop Counter;

/* LATHER - RINSE - REPEAT - Why coders have such nice hair */
}
 

Josh

Member
Its hard to believe but i have since found even smaller addressable leds.
also you can scroll on a single display too.


C++:
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>

#define PIN 6
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(5, 8, PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
  NEO_GRB            + NEO_KHZ800);

void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(20);
  matrix.setTextColor(matrix.Color(255, 0, 0));
 
}

int x = matrix.width();
int pass = 0;
char message[] ="I scroll with the best of them.";

void loop() {
  matrix.fillScreen(0);
  matrix.setCursor(x, 0);
  int scollPixels = (-6 * (strlen(message)));
  matrix.print(message);
  if(--x < scollPixels ) {
    x = matrix.width();
    if(++pass >= 3) pass = 0;
  }
  matrix.show();
  delay(70);
}
 

VK3ZYZ

Moderator
Staff member
That code is great Josh :)
I could not figure out what to change to get the orientation correct.
 
Last edited:

VK3ZYZ

Moderator
Staff member
I just modded some code for this next club meeting.
labels are easier to understand than just numbers so....
Code:
#define panelWidth   5
#define panelHeight  8
#define PIN 5
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(panelWidth, panelHeight, PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS    + NEO_MATRIX_ZIGZAG,
  NEO_GRB            + NEO_KHZ800);
 
Top