MD_Max72xx.h - 8x8 Led Matrix - Print an Array with 90 degree rotation

Hello All

First time poster here.

Been using the MD_parola lib for scrolling text and its working well, including custom fonts that i have made. Many Thanks Marco.

I now would like to display custom STATIC fonts that i have made using this font editor MD_MAX72XX Font Editor, so all good there.

So static font and i can over print them to make some of the 64 leds move, clock face and battery monitor in my case

MY PROBLEM

These fonts are rotated 90 degrees from how they where drawn. I have looked in to the mx.transform(md_max72xx::trc) command but cant work out how to use it.

So the clock face should start with its hands vertical and the battery should be horizontal with the pointed and at the right.

My 4 way matrix has the DATA in on the right hand side and the HARDWARE_TYPE MD_MAX72XX::FC16_HW was worked correctly for all other Parola scrolling text and custom fonts that i have made. I did tyy the other three types but that did not solve the issue.

AM I DOING IT WRONG
I may of course be going about this the totally wrong way?

I say this as i have these two images already in a custom_font.h file but had to convert them in to bytes to try and use them here.

I feel there is an easier way but have not found it yet?

I have looked at the MD_Max72xx_Shift example but that deals with letters and not in my case bytes.

I am also looking into nested loops to reduce the amount of code.

Any help and guidance most welcome

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

#define  delay_t  500  // in milliseconds


// Using a Wemos D1 Mini

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES   4
#define CLK_PIN       14
#define DATA_PIN      13
#define CS_PIN        15

MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

unsigned char i;
unsigned char j;

// clock face
unsigned char clock1[8][7] = {          // row x colums
  124, 130, 130, 158, 138, 134, 124,
  124, 130, 130, 158, 146, 146, 124,
  124, 130, 130, 158, 162, 194, 124,
  124, 130, 130, 254, 130, 130, 124,
  124, 194, 162, 158, 130, 130, 124,
  124, 146, 146, 158, 130, 130, 124,
  124, 134, 138, 158, 130, 130, 124,
  124, 130, 130, 158, 130, 130, 124,
};

// battery 8x8
unsigned char batt1[8][8] = {                 // row x columns
  252, 132, 132, 132, 132, 132, 204, 120,     // 21
  252, 252, 132, 132, 132, 132, 204, 120,     // 22
  252, 252, 252, 132, 132, 132, 204, 120,     // 23
  252, 252, 252, 252, 132, 132, 204, 120,     // 24
  252, 252, 252, 252, 252, 132, 204, 120,     // 25
  252, 252, 252, 252, 252, 252, 204, 120,     // 26
  252, 252, 252, 252, 252, 252, 252, 120,     // 27
};

void setup() {
  mx.begin();
  mx.control(MD_MAX72XX::INTENSITY, 2);
  mx.clear();
}

void loop() {
  drawClock();
  drawBatt();
}

void drawClock() {

  for (j = 1; j <= 7; j++) {
    {
      for (i = 1; i <= 8; i++)
        mx.setRow(0,0,i, clock1[j][i - 1]);    //the two zero only will allow the first matrix to light
      delay(500);
    }
  }
  mx.clear();
}


void drawBatt() {

  // a bit of an issue here as the icons are rotated so my comments may not be true

  for (j = 0; j <= 7; j++) {                // colunms
    {
      for (i = 0; i <= 8; i++)              //rows
        mx.setRow(0,0,i, batt1[j][i]);      //the two zero only will allow the first matrix to light
      delay(500);
    }
  }
  mx.clear();
  delay(10);
}

You should use the buffer version of transform to rotate only one 8x8 module (0 in your case)
bool transform (uint8_t buf, [transformType_t ttype)

Your call to setRow() seems to have one additional parameter, The correct syntax would be
bool setRow(uint8_t buf, uint8_t r, uint8_t value)

Have you tried using setColumn() instead of setRow(), with appropriate loop index changes, to see if the rotation problem is fixed?

I feel there is an easier way but have not found it yet?

You may find it easier to define a custom font with each character one element of the clock/battery and then just load the characters. The library can do most of the work for you then.

Thanks Marco

Though it took me a while i have done it thanks to you reply. I used setColumn and changed the maths

Yes i have already been working on using FONTS and it works very well, but was finding some coding problems with having scrolling and static fonts/ICONS like i have made above.

Below is the new code that now has the FONTS that i made the correct way around.

Thanks for your guidance, I like to understand how things works.

I will now have a go using the Transform Code

I am charting my progress using Youtube videos, which i hope will help people understand using these matrix units. I still have a long way to go but I feel my videos are not just showing your great example sketches but how to use the code to do stuff

Max7219 MD_parola & MD_Max72xx videos

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

#define  delay_t  500  // in milliseconds

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN   14
#define DATA_PIN  13
#define CS_PIN    15

MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

unsigned char i;
unsigned char j;

// clock face
unsigned char clock1[9][7] = {          // row x colums
  124, 130, 130, 158, 130, 130, 124,   // 1
  124, 130, 130, 158, 138, 134, 124,   // 2
  124, 130, 130, 158, 146, 146, 124,   // 3
  124, 130, 130, 158, 162, 194, 124,   // 4
  124, 130, 130, 242, 138, 134, 124,   // 5
  124, 194, 162, 146, 138, 134, 124,   // 6
  124, 146, 146, 146, 138, 134, 124,   // 7
  124, 134, 138, 146, 138, 134, 124,   // 8
  124, 130, 130, 158, 138, 134, 124,   // 9
};

// battery 8x6
unsigned char batt1[6][8] = {                       // row x columns
  252, 132, 132, 132, 132, 132, 252, 120,  // 21
  252, 252, 132, 132, 132, 132, 252, 120,  // 22
  252, 252, 252, 132, 132, 132, 252, 120,  // 23
  252, 252, 252, 252, 132, 132, 252, 120,  // 24
  252, 252, 252, 252, 252, 132, 252, 120,  // 25
  252, 252, 252, 252, 252, 252, 252, 120,  // 26
};

// padlock 8x6
unsigned char padlock[5][6] = {                       // row x columns
  240, 156, 146, 146, 156, 240,   // 206
  240, 150, 145, 145, 158, 240,   // 207
  240, 156, 146, 146, 156, 240,   // 206
  240, 150, 145, 145, 158, 240,   // 207
  240, 156, 146, 146, 156, 240,   // 206
};


void setup() {
  mx.begin();
  mx.control(MD_MAX72XX::INTENSITY, 2);
  mx.clear();
}

void loop() {
    drawClock();
    drawBatt();
    drawPadlock();
  drawBatt1();
}

void drawClock() {
  for (i = 0; i <= 8; i++) {                          // because we have 9 fonts to draw
    {
      for (j = 0; j <= 6; j++)                        // as we have 7 columns of data
        mx.setColumn( 0, j + 1, clock1[i][6 - j]);    //0 for second matrix, j+1 for start column,data
      delay(500);
    }
  }
  mx.clear();
  delay(delay_t );
}


void drawBatt() {

  for (i = 0; i <= 5; i++) {                       // because we have 6 font to draw
    {
      for (j = 0; j <= 7; j++)                    // as we have 8 columns of data
        mx.setColumn( 1, j, batt1[i][7 - j]);     //1 for second matrix, j for start column,data
      delay(500);
    }
  }
  mx.clear();
  delay(delay_t );
}

void drawPadlock() {
  for (i = 0; i <= 4; i++) {                        // because we have 5 fonts to draw
    {
      for (j = 0; j <= 5; j++)                      // as we have 6 columns of data
        mx.setColumn( 2, j + 2, padlock[i][5 - j]); //2 for second matrix, j+2 for start column,data
      delay(delay_t );
    }
  }
  mx.clear();
  delay(delay_t );
}

//working but 180 degree out, left it here for referance to show the maths
void drawBatt1() {
  for (i = 0; i <= 5; i++) {
    {
      for (j = 0; j <= 7; j++)
        mx.setColumn( 0, j, batt1[i][j]);  //zero only will allow the first matrix to light
      delay(delay_t );
    }
  }
  mx.clear();
  delay(delay_t );
}

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