Extending 8x8 led matrix to 16x16

Hi
I have a 8x8 led matrix(max7219) where the individual leds are selected by two potentiometers and two switches.Pot 1 selects up down.pot 2 selects left right and the two switches select or cancel the led at the current position.This is to display the on/off status of some octal switches eventually.
I'm struggling to find some information how to adapt this sketch so I can use more 8x8's to create a 16x16 and 24x24 display.
I have 4 8x8's laid out like............

1....2....
3....4....

obviously at the moment I get the same thing on all them

I'd be grateful if anyone could advise me or point me in the right direction as to what I need to change in the sketch

/* This sketch detects analog signals from the potentiometers
  and sends it to the serial monitor */

//initialize variable for x and y values on the potentiometers and the pushbuttons at digital pin 4 and 7
int UD;
int LR ;
int button_a = 4;
int button_b = 7;


bool stored_state [8][8];

int last_x, last_y;

#include "LedControl.h" //  importing the library
// DIN to 10, CLK to 12, CS to 11
LedControl lc = LedControl(10, 12, 11, 0);

void setup() {
  Serial.begin(9600);
  lc.shutdown(0, false); // turn off power saving, enables display
  lc.setIntensity(0, 8); // sets brightness (0~15 possible values)
  lc.clearDisplay(0);// clear screen
  pinMode(button_a, INPUT); // button is input
  digitalWrite(button_a, HIGH); // initalize button as ON
  pinMode(button_b, INPUT); // button is input
  digitalWrite(button_b, HIGH); // initalize button as ON


}

void loop() {
  UD = analogRead(A1); // read analog value at pin A1 and stores as UD
  LR = analogRead(A0);  // read analog value at pin A0 and stores as LR
  int stateA = digitalRead(button_a); //determines the state of button_a (HIGH or LOW)
  int stateB = digitalRead(button_b); //determines the state of button_b (HIGH or LOW)
  // scales down the value from 0-1023 to 0-7
  char x_translate = map(LR, 0, 1023, 7, 0);
  char y_translate = map(UD, 0, 1023, 0, 7);

  if ( (last_x != x_translate) || (last_y != y_translate) )
  {
    // the position has moved so we need to restore previous state
    lc.setLed(0, last_x, last_y, stored_state [last_x][last_y] );
  }

  last_x = x_translate;
  last_y = y_translate;

  Serial.print ("Button_a=");
  Serial.print(stateA, DEC);
  Serial.print ("Button_b=");
  Serial.print(stateB, DEC);
  Serial.print(", UD = ");
  Serial.print(UD, DEC);
  Serial.print(", LR = ");
  Serial.print(LR, DEC);
  Serial.print(", x = ");
  Serial.print(x_translate, DEC);
  Serial.print(", y = ");
  Serial.println(y_translate, DEC);

  // clears display whenever a new value is updated
  /// --> dont do this!  lc.clearDisplay(0);

  // just set led in new joystick position
  lc.setLed(0, x_translate, y_translate, true);

  // if button_a is pressed, store it
  if (stateA == 1) {
    stored_state [last_x][last_y] = true;
  }

  // if button_b is pressed, delete it
  if (stateB == 1) {
    stored_state [last_x][last_y] = false;
  }

  delay(150); //Mess with delay to tweak accuracy
}
LedControl lc = LedControl(10, 12, 11, 0);

The last parameter of the constructor specifies how many max chips are connected. You seem to be giving it zero, so I'm a little surprised that works... Anyway, for a 16x16 you need to make that 4. The maximum that the library can support is 8 max chips, so for 24x24 matrix, you will have to modify the library or change to another library (or not use a library at all...)

EDIT: It seems that the library assumes 8 chips are attached if you give it a zero:

    if(numDevices<=0 || numDevices>8 )
        numDevices=8;
    maxDevices=numDevices;

So in your sketch, it will be assuming 8 max chips are connected.

I have the parameter set to 4 now but I still have 4 identical displays rather than one big display

Yes, I gave you the first step. You have a few miles still to go.

Yeah.More like a few thousand miles to go :slight_smile:

I think I've worn google and this forum out searching for a similar project.Some are close like scrolling text etc but no cigar

Forget "ledcontrol".

You need to be using the "parola" library for these arrays. It is in the IDE library manager, with examples.

The MD_MAXPanel library may be an option. It would allow you to address each LED by it's x,y coordinates on the display.

Links to my code repository in the signature block.

Thanks guys.That's great info.