How to read Serial data when multiple functions are Running? I want to halt the execution of that code, when arduino is receiving serial data for the execution. Right now the Serial data runs when the other code has completed its execution. How can I do it ?

void loop() { 
    dmd.setBrightness(brighVal); // set the brightness to led matrix
    scroll();  //function to scroll message

}
void serialEvent() {
  while (Serial.available()) {
    Jsondata = Serial.readString(); //reading json data from APP
    DynamicJsonBuffer jsonBuffer;
    Serial.println(Jsondata);
    JsonObject&amp; root = jsonBuffer.parseObject(Jsondata);
    if (root.containsKey("BiM")) {
      brighVal = root["BiM"];
      switch (brighVal) {   // set's the value of brightness according to brighVal
        case 0:
          brighVal = 2;
          break;
        case 1:
          brighVal = 10;
          break;
        case 2 :
          brighVal = 25;
          break;
        case 3 :
          brighVal = 200;
          break;
      }
    }
  }
}
void scroll() {
  dmd.clearScreen( true );
  dmd.selectFont(Arial_Black_16);
  dmd.drawMarquee("Scrolling Text", 17, (32 * DISPLAYS_ACROSS) - 1, 0);
  long start = millis();
  long timer = start;
  boolean ret = false;
  while (!ret) {
    if ((timer + 30) &lt; millis()) {
      ret = dmd.stepMarquee(-1, 0);
      timer = millis();
    }
  }
}
Then let scroll return immediately 

void scroll() {
    static long timer = 0;
    static boolean scroll = true;
    if(scroll){
        dmd.clearScreen( true );
        dmd.selectFont(Arial_Black_16);
        dmd.drawMarquee("Scrolling Text", 17, (32 * DISPLAYS_ACROSS) - 1, 0);
        scroll = false;
        timer = millis()
    }else {
        if ((millis() - timer) &gt; 30)  {
            scroll = dmd.stepMarquee(-1, 0);
            timer = millis();
        }
    }
}


The static keyword means that the value of the variable will be kept across calls.

I used the fact that it will be called in a loop to remove the while loop inside. I split the function up into 2 parts: The reset and the update. We first run the reset to init the marquee. After the reset it will set the boolean so the next time it will enter the update part. Then I used the exit condition of the original loop to make it reenter the update part next time.