Daisy Chain MAX7219 code how to ? help ! [SOLVED]

hello guys,
i am trying to make a daisy chain MAX7219 codes work,
i have 2 MAX7219 chained together, the first has 2 double digit CA 7-segment display connected to it and the second has 1 single digit CA 7-segment display connected to it,

when i try and down load count up codes for 1 MAX7219 it works for all the 7-segment in the same time, of course for 1 digit it displays 1 number

so now i am trying to make a count alone for the single digit and another count up for the other MAX7219

I make a first version of codes trying to understand how it works, when i uploaded the single digit on the second MAX7219 goes off and the other display continue working normally, so i need please to know how this works and what should be done ?

here are my codes :

//We always have to include the library
#include <LedControl.h>

/*
 Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
 pin 12 is connected to the DataIn 
 pin 11 is connected to the CLK 
 pin 10 is connected to LOAD 
 We have only a single MAX72XX.
 */
LedControl lc=LedControl(12,11,10,2,true); //true for Common Anode

void setup() {
  /*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
  //First MAX7219
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,15);
  /* and clear the display */
  lc.clearDisplay(0);
  
  //Second MAX7219
  lc.shutdown(1,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(1,15);
  /* and clear the display */
  lc.clearDisplay(1);
  
  Serial.begin(9600);
}


/*
 This method will display the characters for the
 word "Arduino" one after the other on digit 0. 
 */

void displayCount(){
  int i;
  int ones;
  int tens;
  int hundreds;
  int thousands;
  
  for(i=0; i<10000; i++){
    //must add a new variable which is a here to store value of i in it, 
    //we should not mess with the i because it's for the for() loop
    int a = i;
    ones=a%10;
    a=a/10;
    tens=a%10;
    a=a/10;
    hundreds=a%10;
    a=a/10;
    thousands=a;
    lc.setDigit(0, 0, ones, false);
    lc.setDigit(0, 1, tens, false);
    lc.setDigit(0, 2, hundreds, false);
    lc.setDigit(0, 3, thousands, false);
    
    delay(100);
    
  }
  
  for(i=0; i<10; i++){
    //must add a new variable which is a here to store value of i in it, 
    //we should not mess with the i because it's for the for() loop
    int a = i;
    ones=a;
    lc.setDigit(1, 0, ones, true);
    
    
    delay(100);
    
  }
  
}//-------- end of void displayCount()



void loop() { 
  displayCount();

}

a little update

i managed to make something come up now after i changed this function into the new one the single digit is counting and the double digit displays make a count ++ every time the cycle of the single digit finish counting from 0 to 9

first good step but not what needed, i need the 7-segments displays to be totally independent

void displayCount(){
  int i;
  int j;
  int ones;
  int tens;
  int hundreds;
  int thousands;
  
  for(i=0; i<10000; i++){
    //must add a new variable which is a here to store value of i in it, 
    //we should not mess with the i because it's for the for() loop
    int a = i;
    ones=a%10;
    a=a/10;
    tens=a%10;
    a=a/10;
    hundreds=a%10;
    a=a/10;
    thousands=a;
    lc.setDigit(0, 0, ones, false);
    lc.setDigit(0, 1, tens, false);
    lc.setDigit(0, 2, hundreds, false);
    lc.setDigit(0, 3, thousands, false);
    
    for(j=0; j<10; j++){
    //must add a new variable which is a here to store value of i in it, 
    //we should not mess with the i because it's for the for() loop
    int a = j;
    ones=a;
    lc.setDigit(1, 0, ones, false);
    
    
    delay(100);
    
  }
    
    //delay(50);
    
  }
  
  
  
}//-------- end of void displayCount()

SOLUTION :

what i learned is that when i make a count down or up it's different than just displaying numbers or characters coming from some input, so when i removed the count it worked here are the codes :

void displayCount(){
  int i;
  int j;
  int ones;
  int tens;
  int hundreds;
  int thousands;
  
  
  int a = 5423;
  ones=a%10;
  a=a/10;
  tens=a%10;
  a=a/10;
  hundreds=a%10;
  a=a/10;
  thousands=a;
  lc.setDigit(0, 0, ones, false);
  lc.setDigit(0, 1, tens, false);
  lc.setDigit(0, 2, hundreds, false);
  lc.setDigit(0, 3, thousands, false);

  lc.setDigit(1, 0, 6, false);
 
  
  
  
}//-------- end of void displayCount()

What do you call a counter that is stuck on 6?

The displays are totally independed.

Your 'for loops with delay' :cry: dictates the interlock
(after your changes now you even interlock the display of the digits).

Get rid of all delays, use millis,
then you can do more than one thing at a time.

Amen.

Whandall:
What do you call a counter that is stuck on 6?

The displays are totally independed.

Your 'for loops with delay' :cry: dictates the interlock
(after your changes now you even interlock the display of the digits).

Get rid of all delays, use millis,
then you can do more than one thing at a time.

Amen.

Amen hahahahahaha !

yes i must because the damn delays are a pain the A **

well i tried now to add 2 tactile buttons one will let the single digit add 1 each time it's clicked and the other tactile subtract 1 when it is clicked but what is happening is that the single digit turns off at a certain number i don't know what is happening
here are the codes :

//We always have to include the library
#include <LedControl.h>

/*
 Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
 pin 12 is connected to the DataIn 
 pin 11 is connected to the CLK 
 pin 10 is connected to LOAD 
 We have only a single MAX72XX.
 */
LedControl lc=LedControl(12,11,10,2,true); //true for Common Anode

//Buttons Pins
const byte gearUp_Button = 8; //Push Button that turns the Top red LEDs on
const byte gearDown_Button = 9; //Push Button that turns the Bottom blue LEDs on

boolean lastGearUp = LOW;
boolean currentGearUp = HIGH;
boolean gearUp = false;

boolean lastGearDown = LOW;
boolean currentGearDown = HIGH;
boolean gearDown = false;

//Gear Number
int GearBox = 0;

void setup() {
  /*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
  //First MAX7219
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,15);
  
  
  //Second MAX7219
  lc.shutdown(1,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(1,15);
  
  
  pinMode( gearUp_Button, INPUT_PULLUP ); //RedLeds Button
  pinMode( gearDown_Button, INPUT_PULLUP ); //BlueLeds Button
  
  Serial.begin(9600);
}

  //Debounce Function
  boolean debounce(boolean last, int button)
  {
    boolean current = digitalRead(button);
    if(last != current)
    {
      delay(5);
      current = digitalRead(button);
    }
    return current;
  }


/*
 This method will display the characters for the
 word "Arduino" one after the other on digit 0. 
 */

void displayCount(){
  int i;
  int j;
  int ones;
  int tens;
  int hundreds;
  int thousands;
  
  
  int a = 5423;
  ones=a%10;
  a=a/10;
  tens=a%10;
  a=a/10;
  hundreds=a%10;
  a=a/10;
  thousands=a;
  
 
  //display of the numbers of Displays
  lc.setDigit(0, 0, ones, false);
  lc.setDigit(0, 1, tens, false);
  lc.setDigit(0, 2, hundreds, false);
  lc.setDigit(0, 3, thousands, false);

  lc.setDigit(1, 0, GearBox, false); //Single digit
  
  Serial.println(GearBox);
  
}//-------- end of void displayCount()



void loop() { 
  if(GearBox >9){
    GearBox = 9;
  }else if(GearBox <0){
    GearBox = 0;
  }
  
  //Start of the gear box codes
  currentGearUp = debounce(lastGearUp, gearUp_Button);
  currentGearDown = debounce(lastGearDown, gearDown_Button);
  
  
  if(lastGearUp == HIGH && currentGearUp == LOW){
     GearBox++;
  }
  
  lastGearUp = currentGearUp;
  
  if(lastGearDown == HIGH && currentGearDown == LOW){
     GearBox--; 
  }
    
  lastGearDown = currentGearDown;
  
  displayCount();
  
  
}// ------ end of void loop()

One more tip:

remove or adjust comments that are relicts.

 We have only a single MAX72XX.
...
  /* Set the brightness to a medium values */
  lc.setIntensity(0,15); // <- MAXIMUM
...
 This method will display the characters for the
 word "Arduino" one after the other on digit 0.

BTW why do you use 2 MAX7219?
I have displays with 8 digits per MAX7219...

Whandall:
BTW why do you use 2 MAX7219?
I have displays with 8 digits per MAX7219...

Sorry for late reply, i didn't notice maybe it has slip
I use it because the first is full 8 digits at the end of my project, in my example no but i had to imagine it's full and try 2 MAX

That's reasonable.

Good Luck!

Whandall:
That's reasonable.

Good Luck!

thank you for the advices :slight_smile: