small library for MAX7219 LED matrix

Hallo,
I have been bought an LED matrix like the picture below.

I use Arduino Nano to display a text and number. The text is "done" and the value number is just float variable 'xy.z' .
I want to getting the smallest code of library that suitable with my display. It is for my consideration related out of memory after I compile. Because I use many library for the other devices. I found the led matrix library is the biggest one.

Please show me the smallest library.

Thank you very much.

Regards

ledmatrix.JPG

ledmatrix.JPG

You don't need a library at all.

Hi Marco,
I was very lucky to get from an expert response :slight_smile: :slight_smile:

I was try the code from Using the MAX7219 in your Projects – Part 2 – Arduino++ to Arduino UNO

but the result appearance is not very good.

I also try the library with good visualization but it need much memory. See my code below:

// Use the MD_MAX72XX library to Print some text on the display
//
// Demonstrates the use of the library to print text.
//
// User can enter text on the serial monitor and this will display as a
// message on the display.

#include <MD_MAX72xx.h>
#include <SPI.h>

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4

#define CLK_PIN   13  // or SCK
#define DATA_PIN  11  // or MOSI
#define CS_PIN    10  // or SS

int value_1 = 10;
float value_2 = 98.8;
float temp1 = 0.0;

int a;
int b;
int tenth;
int unitV;
int per_tenth;

// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// Text parameters
#define CHAR_SPACING  1 // pixels between characters

// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE  15
char message[BUF_SIZE] = "Hello!";
bool newMessageAvailable = true;

void printText(uint8_t modStart, uint8_t modEnd, char *pMsg)
// Print the text string to the LED matrix modules specified.
// Message area is padded with blank columns after printing.
{
  uint8_t   state = 0;
  uint8_t   curLen;
  uint16_t  showLen;
  uint8_t   cBuf[8];
  int16_t   col = ((modEnd + 1) * COL_SIZE) - 1;

  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);
  

  do     // finite state machine to print the characters in the space available

  {
    switch(state)
    {
      case 0: // Load the next character from the font table
        // if we reached end of message, reset the message pointer
        if (*pMsg == '\0')
        {
          showLen = col - (modEnd * COL_SIZE);  // padding characters
          state = 2;
          break;
        }

        // retrieve the next character form the font file
        showLen = mx.getChar(*pMsg++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
        curLen = 0;
        state++;
        // !! deliberately fall through to next state to start displaying

      case 1: // display the next part of the character
        mx.setColumn(col--, cBuf[curLen++]);

        // done with font character, now display the space between chars
        if (curLen == showLen)
        {
          showLen = CHAR_SPACING;
          state = 2;
        }
        break;

      case 2: // initialize state for displaying empty columns
        curLen = 0;
        state++;
        // fall through

      case 3:	// display inter-character spacing or end of message padding (blank columns)
        mx.setColumn(col--, 0);
        curLen++;
        if (curLen == showLen)
          state = 0;
        break;

      default:
        col = -1;   // this definitely ends the do loop
    }
  } while (col >= (modStart * COL_SIZE));

  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
}

void setup()
{
  mx.begin();
}

void loop(){
    value_2 = value_2 + 0.1;
    a = value_2;
    per_tenth = value_2*10 - a*10;
    tenth = value_2 / 10;
    unitV = value_2 - (tenth*10);
    //Serial.print("*C\tObject = ");
    //Serial.println(value_2);

//==================dot matrix

int lt = ((value_1/10)%10);
int rt = (value_1%10);
message[0]=' ';
message[1]=char(tenth)+48;
message[2]=char(unitV)+48;
message[3]='.';
message[4]=char(per_tenth)+48;
message[5]='C';
message[6]='\0';

printText(0, MAX_DEVICES-1, message);

delay(500);

if (per_tenth == 0){
//printText(0, MAX_DEVICES-1, "Ready");
message[0]='R';
message[1]='e';
message[2]='a';
message[3]='d';
message[4]='y';
message[5]='\0';
printText(0, MAX_DEVICES-1, message);

delay(2000);  
}
if (value_2>99.5){
  value_2 = 10.0;
}
}

May the code make more simple? So the memory usage can more reduce.

thank you very much

regards

but the result appearance is not very good

What was 'not very good'? You need to give details. The example in the blog post is meant to be the starting point for your own code, not a fully working, scrolling text display.

The library is the library and it is difficult to make it smaller unless you want to reduce the functionality (which you can do, but that will be up to you to work through the code).

Hi Marco,
You're right the example in the blog was the very basic code. The display will one character in the one module so if I put a decimal point will look have big space and not proportional.
Any way many thank for help.

regards

Check it, maybe it will help you.