ledControl MAX72XX - no code runs after sequence - help why?

Hi all
I am running a sequence which includes a 'countdown timer' on a LED matrix.
After this has run, no other code will run. The plan is to have a relay activate.
No matter what I do, nothing will run after the matrix sequence has complete.
Any help would be greatly appreciated - hopefully just missing something simple.
many thanks


int buttonPin2 = 3;
int buttonPin3 = 4;
int buttonPin1 = 2;
int redPin = 12;
int yellowPin = 11;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int bluePin = 13;
#include <Servo.h>
Servo myservo;
Servo myservo2;
int pos = 0;                                                      
#include <LedControl.h>
int DIN = 8;
int CS =  7;
int CLK = 10;
LedControl lc=LedControl(DIN,CLK,CS,0);


void setup() {
  // put your setup code here, to run once:

pinMode(yellowPin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
 lc.shutdown(0,false);       //The MAX72XX is in power-saving mode on startup
 lc.setIntensity(0,15);      // Set the brightness to maximum value
 lc.clearDisplay(0);  

myservo.attach(9);
myservo2.attach(6);

 
}

void loop() {
myservo2.write (0);

buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);


if (buttonState1 && buttonState2 && buttonState3 == HIGH) {


digitalWrite(yellowPin, HIGH);
digitalWrite(redPin, HIGH);
digitalWrite(bluePin, HIGH);
delay(500);
digitalWrite(yellowPin, LOW);
delay(500);
digitalWrite(redPin, LOW);
delay(500);
digitalWrite(bluePin, LOW);


myservo.write (180);
delay (100);
myservo.write (170);   
delay (100);    
myservo.write (160);   
delay (100);  
myservo.write (150);   
delay (100);
myservo.write (140);   
delay (100);  
myservo.write (130);   
delay (100);  
myservo.write (120);   
delay (100);    
myservo.write (110);   
delay (100);  
myservo.write (100);   
delay (100);  
myservo.write (90);   
delay (100); 
myservo.write (80);   
delay (100);  
myservo.write (70);   
delay (100); 
myservo.write (60);   
delay (100); 
myservo.write (50);   
delay (100);   
myservo.write (40);   
delay (100);    
myservo.write (30);   
delay (100);  
myservo.write (20);   
delay (100);  
myservo.write (10);   
delay (100); 
myservo.write (0);   
delay (100); 
myservo.write (10);   
delay (100); 
myservo.write (20);   
delay (100);  
myservo.write (30);   
delay (100);  
myservo.write (60);   
delay (100); 
myservo.write (20);   
delay (100); 
myservo.write (180);
delay (100);
myservo.write (170);   
delay (100);    
myservo.write (160);   
delay (100);  
myservo.write (150);   
delay (100);
myservo.write (140);   
delay (100);  
myservo.write (130);   
delay (100);  
myservo.write (120);   
delay (100);    
myservo.write (110);   
delay (100);  
myservo.write (100);   
delay (100);  
myservo.write (90);   
delay (100); 
myservo.write (80);   
delay (100);  
myservo.write (70);   
delay (100); 
myservo.write (60);   
delay (100); 
myservo.write (50);   
delay (100);   
myservo.write (40);   
delay (100);    
myservo.write (30);   
delay (100);  
myservo.write (20);   
delay (100);  
myservo.write (10);   
delay (100); 
myservo.write (0);   
delay (100); 
myservo.write (10);   
delay (100); 
myservo.write (20);   
delay (100);  
myservo.write (30);   
delay (100);  
myservo.write (60);   
delay (100); 
myservo.write (20);   
delay (100); 


ledMatrix();
  
myservo2.write (90);



}
else 
    {
      digitalWrite(yellowPin, LOW);
      digitalWrite(redPin, LOW);
      digitalWrite(bluePin, LOW);

      myservo2.write (0);



    }
    
}



void printByte(byte character [])
{
  int i = 0;
  for(i=0;i<8;i++)
  {
    lc.setRow(0,i,character[i]);
  }
}


void ledMatrix(){
byte a[8]=   {0, 0x5e, 0x52, 0x52, 0x52, 0x52, 0x5e, 0,}; //makes 10
    byte b[8]= {0x0, 0x3c, 0x24, 0x24 , 0x3c, 0x4, 0x3c, 0x0,}; //makes 9
    byte c[8]= {0x18, 0x24, 0x24, 0x18, 0x24, 0x24, 0x18, 0x0,}; //makes 8
    byte d[8]=   {0x0, 0x3c, 0x4, 0x4, 0x4, 0x4, 0x4, 0x0,}; //makes 7
    byte e[8] = {0x0, 0x3c, 0x20, 0x20, 0x3c, 0x24, 0x3c, 0x0,}; //number 6
    byte f[8] = {0x0, 0x3c, 0x20, 0x3c, 0x4, 0x4, 0x3c, 0x0,}; //number 5
    byte g[8]=   {0x0, 0x24, 0x24, 0x3c, 0x4, 0x4, 0x4, 0x0,}; //makes 4
    byte h[8]= {0x0, 0x38, 0x4, 0x4, 0x38, 0x4, 0x4, 0x38,}; //makes star 3 
    byte i[8]= {0x0, 0x18, 0x24, 0x4, 0x18, 0x20, 0x3c, 0x0,}; //makes 2
    byte j[8] = {0x0, 0x8, 0x18, 0x8, 0x8, 0x8, 0x1c, 0x0,}; //number 1
    byte k[8] = {0x0, 0x3c, 0x24, 0x24, 0x24, 0x24, 0x3c, 0x0,}; //number 0
 printByte(a);
     
    delay(1000);

    printByte(b);
    
    delay(1000);

    printByte(c);
    
    delay(1000);

    printByte(d);    

    delay(1000);

    printByte(e);

    delay(1000);

    printByte(f);

    delay(1000);

    printByte(g);

    delay(1000);

    printByte(h);

    delay(1000);

    printByte(i);

    delay(1000);

    printByte(j);

    delay(1000);

    printByte(k);

    delay(1000);

   lc.clearDisplay(0);



  
}




  
    

Your topic has been moved to a more suitable location on the forum. Introductory Tutorials is not for questions but for tutorials that you write.

The code that you posted has nothing to execute after you call ledMatrix() so how do you know it does not run?

Hi, thanks for your help here.
After ledMatrix() I had tried simply activating an led or a servo (I changed the sample code to better reflect what I had tried)
Many thanks

Some things i did forget to ask

  1. Which Arduino
  2. Which servos do you use?
  3. Which display (or how many leds controlled)
  4. How is everything powered? If you powered the display and the servos from your Arduino, that can be a possible cause.

Some steps that you can take to identify the issue

  1. Disconnect servos and remove all servo code; try to control a LED (e.g. the built-in LED). E.g. the below will blink the built-in LED.
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));
delay(500);
  1. Use serial prints to find out if the ledMatrix function gets stuck somewhere; e.g. add the below after each step in ledMatrix()
    printByte(a);
    Serial.print("A on display");
    Serial.flush();
    delay(1000);
    printByte(b);
    Serial.print("B on display");
    Serial.flush();
    delay(1000);

The flush() is used to make sure that your code is not already further before the serial monitor shows the text.

  1. Add a serial.print in setup() to see if your Arduino restarts
void setup() {
  Serial.begin(115200);
  while(!Serial);
  Serial.println("Arduino started");

  YOUR CODE HERE

If you have a code problem (I don't immediately see one) or a power problem, you will see "Arduino started" more than one time.

@ChockymilK

if you use

  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);

you need external pull down resistors to get a stable signal HIGH or LOW.
Do you have external pull downs on your buttons?

as already mentioned, add Serial Output to debug your code.
this is just an example

constexpr uint8_t buttonPin2 = 3;
constexpr uint8_t buttonPin3 = 4;
constexpr uint8_t buttonPin1 = 2;
constexpr uint8_t redPin = 12;
constexpr uint8_t yellowPin = 11;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
constexpr uint8_t bluePin = 13;
#include <Servo.h>
Servo myservo;
Servo myservo2;
int pos = 0;
#include <LedControl.h>
constexpr uint8_t DIN = 8;
constexpr uint8_t CS = 7;
constexpr uint8_t CLK = 10;
//LedControl lc = LedControl(DIN, CLK, CS, 0); // this makes no sense ... you should have more then 0 devices!
LedControl lc = LedControl(DIN, CLK, CS);

void setup() {
  Serial.begin(115200);
  Serial.println(F("Arduino started"));
  // put your setup code here, to run once:
  pinMode(yellowPin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(buttonPin1, INPUT);  // this will need external pull down resistors!!!
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  lc.shutdown(0, false);   //The MAX72XX is in power-saving mode on startup
  lc.setIntensity(0, 15);  // Set the brightness to maximum value
  lc.clearDisplay(0);
  myservo.attach(9);
  
  myservo2.attach(6);
}
void loop() {
  myservo2.write(0);
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);

  Serial.print(F("b1:")); Serial.print(buttonState1);
  Serial.print(F("   b2:")); Serial.print(buttonState2);
  Serial.print(F("   b3:")); Serial.println(buttonState3);
  
  if (buttonState1 && buttonState2 && buttonState3 == HIGH) {
    Serial.println(F("end if condition"));
    digitalWrite(yellowPin, HIGH);
    digitalWrite(redPin, HIGH);
    digitalWrite(bluePin, HIGH);
    delay(500);
    digitalWrite(yellowPin, LOW);
    delay(500);
    digitalWrite(redPin, LOW);
    delay(500);
    digitalWrite(bluePin, LOW);
    // from 180 to 
    for (int i = 180; i>0; i-=10)
    {
      myservo.write(i);
      delay(100);
    }
    for (int i = 0; i<180; i+=10)
    {
      myservo.write(i);
      delay(100);
    }
    // removed several others to make code shorter
    
    ledMatrix();

    myservo2.write(90);
    Serial.println(F("end if condition"));
  } else {
    digitalWrite(yellowPin, LOW);
    digitalWrite(redPin, LOW);
    digitalWrite(bluePin, LOW);
    myservo2.write(0);
  }
}

void printByte(byte character[]) {
  int i = 0;
  for (i = 0; i < 8; i++) {
    lc.setRow(0, i, character[i]);
  }
}
void ledMatrix() {
  Serial.println(F("start ledMatrix"));
  byte a[8] = {
    0,
    0x5e,
    0x52,
    0x52,
    0x52,
    0x52,
    0x5e,
    0,
  };  //makes 10
  byte b[8] = {
    0x0,
    0x3c,
    0x24,
    0x24,
    0x3c,
    0x4,
    0x3c,
    0x0,
  };  //makes 9
  byte c[8] = {
    0x18,
    0x24,
    0x24,
    0x18,
    0x24,
    0x24,
    0x18,
    0x0,
  };  //makes 8
  byte d[8] = {
    0x0,
    0x3c,
    0x4,
    0x4,
    0x4,
    0x4,
    0x4,
    0x0,
  };  //makes 7
  byte e[8] = {
    0x0,
    0x3c,
    0x20,
    0x20,
    0x3c,
    0x24,
    0x3c,
    0x0,
  };  //number 6
  byte f[8] = {
    0x0,
    0x3c,
    0x20,
    0x3c,
    0x4,
    0x4,
    0x3c,
    0x0,
  };  //number 5
  byte g[8] = {
    0x0,
    0x24,
    0x24,
    0x3c,
    0x4,
    0x4,
    0x4,
    0x0,
  };  //makes 4
  byte h[8] = {
    0x0,
    0x38,
    0x4,
    0x4,
    0x38,
    0x4,
    0x4,
    0x38,
  };  //makes star 3
  byte i[8] = {
    0x0,
    0x18,
    0x24,
    0x4,
    0x18,
    0x20,
    0x3c,
    0x0,
  };  //makes 2
  byte j[8] = {
    0x0,
    0x8,
    0x18,
    0x8,
    0x8,
    0x8,
    0x1c,
    0x0,
  };  //number 1
  byte k[8] = {
    0x0,
    0x3c,
    0x24,
    0x24,
    0x24,
    0x24,
    0x3c,
    0x0,
  };  //number 0
  printByte(a);
  delay(1000);
  printByte(b);
  delay(1000);
  printByte(c);
  delay(1000);
  printByte(d);
  delay(1000);
  printByte(e);
  delay(1000);
  printByte(f);
  delay(1000);
  printByte(g);
  delay(1000);
  printByte(h);
  delay(1000);
  printByte(i);
  delay(1000);
  printByte(j);
  delay(1000);
  printByte(k);
  delay(1000);
  lc.clearDisplay(0);
  Serial.println(F("end ledMatrix"));
}

Please tell us what you see on your Serial Monitor.

Please show a schematic and a real world picture of your setup.

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