LCD & KeyPad stop working after adding DMD (I2C + SPI)

Hi community! :slight_smile:

Ok, I've been working on P10 panels lately, would love to use a keypad to set the display after going through all the settings I made (speed, language of display, ...)

Everything was running pretty fine before adding the DMD code, once I confirm and click on "#" the message will start scrolling then I can't update it or use both the LCD and the keypad :confused:

I tried to use the goto but I faced the same problem :frowning:

Thanks for you help.

#include <Keypad.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <SPI.h>        
#include <DMD.h>        
#include <TimerOne.h>
#include "AR.h"

#define codeLenght 4 // Give enough room for 3 chars + NULL char

//DMD
#define DISPLAYS_ACROSS 3
#define DISPLAYS_DOWN 1

//LCD
LiquidCrystal_I2C lcd(0x27, 20, 4);//0x27 0x38


//KeyPad
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {A0, A1, A2, A3};

Keypad myKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

char Code[codeLenght];
char Speed;
byte codeCount = 0;
boolean mode = false;
boolean Display = false;
int page;
int value;
char Key;
String language;
String MSG;
unsigned long time;
int n;
boolean ret = false;

DMD dmd(DISPLAYS_ACROSS , DISPLAYS_DOWN);
void ScanDMD(){
  dmd.scanDisplayBySPI();
}

void setup(){
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  myKeypad.addEventListener(keypadEvent);
  Timer1.initialize(3000);       
  Timer1.attachInterrupt(ScanDMD);  
  dmd.selectFont(AR);
  dmd.clearScreen(true);
}

void loop(){
  char key = myKeypad.getKey();
  if(mode){
    if(key == '*'){
      mainMenu();
      page = 0;
    }
    if(page == 0){
      if(key == '1'){
        lanMenu();
      }
      if(key == '2'){//page 3
        page = 2;
        lcd.clear();
        lcd.setCursor(7, 0);
        lcd.print("SPEED");
        lcd.setCursor(2, 1);
        lcd.print("Enter Your Speed");
        lcd.setCursor(12, 3);
        lcd.print("(*) Back");
      }
    }
    if(page == 1){
      if(key == '1'){
        lcd.clear();
        lcd.setCursor(2, 0);
        lcd.print("Language Display");
        lcd.setCursor(7, 1);
        lcd.print("French");
        lcd.setCursor(12, 3);
        lcd.print("(*) Back");
        language = "FR";
      }
      if(key == '2'){
        lcd.clear();
        lcd.setCursor(2, 0);
        lcd.print("Language Display");
        lcd.setCursor(7, 1);
        lcd.print("English");
        lcd.setCursor(12, 3);
        lcd.print("(*) Back");
        language = "EN";
      }
      if(key == '3'){
        lcd.clear();
        lcd.setCursor(2, 0);
        lcd.print("Language Display");
        lcd.setCursor(8, 1);
        lcd.print("Mix");
        lcd.setCursor(12, 3);
        lcd.print("(*) Back");
        language = "MX";
        }
      }
      if(page == 2){
        if(key){
          Speed = key;
          lcd.setCursor(9, 2);
          lcd.print(Speed);
          
        }
      }
    if(key == '#'){
      mode = false;
      Display = true;
      Serial.print("lineId: ");Serial.println(value);
      Serial.print("lineName: ");Serial.println(MSG);
      Serial.print("Language: ");Serial.println(language);
      Serial.print("Speed: ");Serial.println(Speed);
      Serial.print("\n");
      lcd.clear();
    }
  }
  else{
    lcd.setCursor(0,0);
    lcd.print("  Enter Your Code");
  
    if(key){
      Code[codeCount] = key; // store char into data array
      lcd.setCursor(8 + codeCount,2); // move cursor to show each new char
      lcd.print(Code[codeCount]); // print char at said cursor
      codeCount++; // increment data array by 1 to store new char, also keep track of the number of chars entered
    }

    if(codeCount == codeLenght-1){ // if the array index is equal to the number of expected chars, compare data to master
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(Code);
    lcd.setCursor(0, 1);

    value = atoi(Code);
    switch(value){
      case 100:
        mode = true;
        MSG = "Bus Special";
        lcd.print(MSG);
        lcd.setCursor(0, 3);
        lcd.print("(*) Menu    (#) Exit");
        break;
      case 102:
        mode = true;
        MSG = "Bla Bla Bla";
        lcd.print(MSG);
        lcd.setCursor(0, 3);
        lcd.print("(*) Menu    (#) Exit");
        break;
      case 201:
        mode = true;
        MSG = "Bla Bla Bla";
        lcd.print(MSG);
        lcd.setCursor(0, 3);
        lcd.print("(*) Menu    (#) Exit");
        break;
      case 217:
        mode = true;
        MSG = "Bla Bla Bla";
        lcd.print(MSG);
        lcd.setCursor(0, 3);
        lcd.print("(*) Menu    (#) Exit");
        break;
      case 229:
        mode = true;
        MSG = "Bla Bla Bla ";
        lcd.print(MSG);
        lcd.setCursor(0, 3);
        lcd.print("(*) Menu    (#) Exit");
        break;
      default:
        mode = false;
        Display = true;
        value = "\0";
        MSG = "";
        lcd.setCursor(0, 1);
        lcd.print("Invalid Code");
        delay(2000);
        lcd.clear();
        dmd.clearScreen(true);
        break;
    }
    clearCode();
    }
  }
   dmd.drawString(0, -1, String(value).c_str(), 3, GRAPHICS_NORMAL);
   dmd.drawMarquee(MSG.c_str(), strlen(MSG.c_str()), (32*DISPLAYS_ACROSS)-1, -1); //strlen

  time = millis();
    n=0;
    while(n<1){
      while(!ret){
        if((time+30) < millis()){
          ret = dmd.stepSplitMarquee(0,16,30);
          time=millis();
        }
      }
      ret = false;
      n++; 
    }
  dmd.clearScreen(true);
  
}

void keypadEvent(KeypadEvent key){
    switch (myKeypad.getState()){
    case PRESSED:
        
        break;

    case RELEASED:
        if (key == '1' && page == 0) {
            if(mode)page = 1;
        }
        break;

    case HOLD:
        if (key == '*'){
           
        }
        break;
    }
}

void mainMenu(){
  lcd.clear();
  lcd.setCursor(8, 0);
  lcd.print("MENU");
  lcd.setCursor(0, 1);
  lcd.print("(1) Language");
  lcd.setCursor(0, 2);
  lcd.print("(2) Speed");
  lcd.setCursor(12, 3);
  lcd.print("(#) Exit");
}

void lanMenu(){
  lcd.clear();
  lcd.setCursor(6, 0);
  lcd.print("LANGUAGE");
  lcd.setCursor(0, 1);
  lcd.print("(1) FR   (2) EN");
  lcd.setCursor(0, 2);
  lcd.print("(3) MIX");
  lcd.setCursor(12, 3);
  lcd.print("(*) Back");
}

void clearCode(){
  while(codeCount !=0 ){   // This can be used for any array size, 
    Code[codeCount--] = 0; //clear array for new data
  }
  return;
}