Go Down

Topic: Better padding for MAX7219 (Read 139 times) previous topic - next topic

japreja

My Hardware is from here

I am using two of those 8 digit 7 segment displays with a modified LedControl library from GitHub .

When I use the Justification functions from this library, to right Justify, the display is barely readable.  But when I add the necessary padding converting a float to a string, then concatenating the converted string to a string of necessary spaces, then the speed is greatly improved.

I initially started with displaying floats, as in the examples, but reverted to converting the values to strings.

Here is my code:

Code: [Select]

/* This Code uses a modified LedControl library from https://github.com/RiveriaHorizon/LedPrint
 * 
 *  I was experiancing alot of flicker when using the Justification settings so I converted my
 *  float to strings and left padded that string with spaces which allowed for much faster speed
 *  with little to no delay
 * 
 *  I have 2
 */

/** Printing numbers
 *
 */
 
#include <LedPrint.h>

LedPrintJustifiable myLed = LedPrintJustifiable
  (
    11, // DATA PIN
    13, // CLOCK PIN
    10, // CS PIN
    16,  // NUMBER OF DIGITS
    1   // Orientation 0/1, if it looks backwards try the other
  );

LedPrintJustifiable dX;
LedPrintJustifiable dY;

void setup()
{
  // Set Brightness
  myLed.setIntensity(5);
 
  dY = myLed.getSubDisplay(0, 8); // First digit 0, 8 digits - first module (MAX7219)
  dX = myLed.getSubDisplay(8, 8); // First digit 8, 8 digits - second module (MAX7219)

  dX.justify(-1);
  dY.justify(-1);
}

void loop()
{
  float x=0.0001;
  float y=9999.9999;

  for(float i = 0.0000; i<=9999.9999;i=i+1.001)
  {
    String sY = String(i,4);
    String sX = String(i,4);
    if(i<10)
    {
      sX = "   " + sX;
    }
    else if(i>9.9999 && i<100)
    {
      sX = "  " + sX;
    }
    else if(i>99.9999 && i<1000)
    {
      sX = " " + sX;
    }
   
    dX.println(sX);
    dY.println(sY);
    delay(1);
   
  }
 
 
  //dX.println(1234.9876,4);
  //dY.println(9876.1234,4);
  delay(250);
}

void printFloats(){
  // Print some floating point numbers on the right, to 2 decimal places
  myLed.justify(1);
  for(uint8_t x = 1; x < 20; x++)
  {
    //myLed.println((float)(random(0,99999999))/((float)(random(0,9999999))),4);
    myLed.println(100.2349,4);
    delay(250);
  }
}

void printDigitsJustifiedLeft(){
  // Print some numbers left justified
  myLed.justify(-1);
  for(uint8_t x = 1; x < 100; x++)
  {
    myLed.println(x); delay(20);
  }
}

void printDigitsJustifiedLeftWithPadding(){
  // Print some numbers right justified with zero pad
  myLed.justify(1, 0);
  for(uint8_t x = 1; x < 100; x+=9)
  {
    // because of the way the justification works
    // this needs to happen a bit slower so that it doesn't
    // have too much bleed-through of the zero padding when
    // the characters are shifted in
    myLed.println(x); delay(500);
  }
}

void printDigitsJustifiedRight(){
  // Print some numbers right justified
  myLed.justify(1);
  for(uint8_t x = 1; x < 100; x++)
  {
    myLed.println(x); delay(20);
  }
}

void printDigitsJustifiedCenter(){
  // Print some numbers center justified
  myLed.justify(0);
  for(uint8_t x = 1; x < 100; x++)
  {
    myLed.println(x); delay(20);
  }
}



I've never updated a library, or even written one, How can I replace the library's code with my padding method as it seems to work much faster?

By the way, the modified library uses the ICSP pins of the Arduino Uno.

Go Up