Home > database >  is there any way to run two loops?
is there any way to run two loops?

Time:04-02

I can't do the blinking text while having scrolling text at the second row of the i2c lcd in arduino.

I tried creating and naming two loops but it is doing one task then another.

void loop(){
  blinkingloop();
  scrollingloop();
}
  
void blinkingloop(){
  lcd.setCursor(3, 0);
  lcd.print(staticMessage);
  delay(1000);
  lcd.clear();
  delay(500);  

}

void scrollingloop(){
  scrollMessage(1, scrollingMessage, 250, totalColumns);

}

CodePudding user response:

you just have to write all you're code without blocking delay. I can suggest you to use millis . a function that return the number of milliseconds since startup.

try something like that : (a function to print free memory all 10Seconds)

void loop(){
      static int lastFreeMemoryCheck = 0;
    if (millis() - lastFreeMemoryCheck > 10000)
    {
        lastFreeMemoryCheck = millis();
        Serial.print("Free memory: ");
        Serial.print(ESP.getFreeHeap());
        Serial.print(" || Min Free memory: ");
        Serial.println(ESP.getMinFreeHeap());
     }
     // ...
}

CodePudding user response:

I think that the only way to do multiple processes simultaneously is by using multithreading check this project that demonstrates it with an example of an LCD https://create.arduino.cc/projecthub/reanimationxp/how-to-multithread-an-arduino-protothreading-tutorial-dd2c37

  • Related