Making arrays into 2d array

hi so recently i made a code that uses frames(that are being shown as array of rows as in MD_MAX72xx convention

and i cant make the 2d array from those frames
can anyone help?

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


// led display 
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 1

#define CLK_PIN   13  
#define DATA_PIN  11  
#define CS_PIN    10  

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 1

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


//switch
#define button_input A0


const byte T[8] = {
  B11111111,
  B11111111,
  B01111110, 
  B00011000, 
  B00011000, 
  B00011000, 
  B00011000, 
  B00011000 
};

const byte Z[8] = {
  0b11111111,
  0b11111111, 
  0b00001110, 
  0b00011100, 
  0b00111000, 
  0b01110000,
  0b11111111,
  0b11111111
};


void setup() {
  // put your setup code here, to run once:
   pinMode(button_input, INPUT);

  ledDisplay.begin();
  ledDisplay.control(MD_MAX72XX::INTENSITY, 0);
  ledDisplay.clear();
  
}

void loop() {
  
  if(digitalRead(button_input)== HIGH)

>     **byte frams[]  = {Z, T};**

printSpinRun(ledDisplay, frams, 25, 30, 3000);
}

void print_led(MD_MAX72XX display ,byte to_print[]){
  for(int i=0; i<8; i++){
    display.setRow(0, i, to_print[i]);
  }
}

void printSpinRun(MD_MAX72XX display, byte frames[2][8], int max, int min, int maxRepTime){
  int repetitionsLeft = random(max, min);

  while(repetitionsLeft > 0 ){
    print_led(display, frames[repetitionsLeft % (sizeof(frames)/sizeof(frames[0]))]);
    delay(maxRepTime / repetitionsLeft);

    repetitionsLeft--;
  }


}

too much definitions

simplify your sketch to definition of 2 1D arrays for input and 1 2D array for output

The T's are 2Darray[ index ][ 0 ] and the Z's are the .......[ 1 ]

const byte name_me_what_I_am[8][2] = {
  B11111111,  0b11111111,
  B11111111,  0b11111111, 
  B01111110,  0b00001110, 
  B00011000,  0b00011100, 
  B00011000,  0b00111000, 
  B00011000,  0b01110000,
  B00011000, 0b11111111,
  B00011000,  0b11111111 
};

Although it does work as is, for making clear where the rows are, one usually add extra {}

const byte name_me_what_I_am[][2] = {
  {0b11111111,  0b11111111},
  {0b11111111,  0b11111111}, 
  {0b01111110,  0b00001110}, 
  {0b00011000,  0b00011100}, 
  {0b00011000,  0b00111000}, 
  {0b00011000,  0b01110000},
  {0b00011000,  0b11111111},
  {0b00011000,  0b11111111}
};

(And OP should decide either for arduino’s Bxxxxxxxx or the standard 0bxxxxxxx for coherence)

Not sure this is what makes sense though - looking into the shapes the first column looks like a T letter with a fat top bar and the second column looks like a Z letter.

It might be easier (contiguous memory access) to have the array reversed and have a size listed as [2][8] (and lay the bytes the right way)

I would have a struct or class called Letter including just an array of 8 bytes and then the collection of glyphs would be an array of Letters. It would be defined in the same way as the [2][8] array but you could have functions tied to the struct for display - and add other attributes like what letter does this represent

That is more clear. Maybe call the 2x8 array font?

Yeah or something like this

struct Letter { // or better with attribute packed
  const char character;
  const uint8_t bitmap[8];
};

const Letter font[] {
  {'T', 0b11111111, 0b11111111, 0b11111111, …, 0b00011000},
  {'Z', 0b11111111, 0b11111111, 0b00001110, …, 0b11111111},
  …
};

(using my iPhone at the moment so too lazy to enter type all the bytes)

Trying not to type all... oops!

fixed :wink:

1 Like

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