-1

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);

}
Bonn
  • 21
  • 1
  • 4
  • Generally you should use `millis()` to deteremine current time and do works according to the time. What is `scrollMessage`? – MikeCAT Apr 01 '22 at 13:10
  • That's right, code runs in order of operation; try debugging and seeing step-by-step; You'd need to apply some tricks to get your expected output but looping both sets together if possible? – BGPHiJACK Apr 01 '22 at 13:10
  • You could run two threads and call them both at the same time, but this tends to make the process more asynchronous with both threads returning at different times all together. Queueing and all sorts will help. – BGPHiJACK Apr 01 '22 at 13:12
  • Instead of attempting to do multiple things in parallel, especially delays, consider doing less things in smaller steps. For example you could check the current timestamp (using the `millis()` function as suggested) and if enough time have passed you do "set cursor" and "print static message" *and* scroll *one* character of the "scrolling message". Then the `loop` function returns, and you again wait until enough time has passed before you clear the LCD, and scoll the next character of the "scolling message". And so on. – Some programmer dude Apr 01 '22 at 13:14

2 Answers2

0

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());
     }
     // ...
}
Antoine Laps
  • 111
  • 5
0

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

fub32
  • 23
  • 5
  • This is not multithreading but an lib that hide thé same solution that i describe. Use a real multithreading with rtos for this task is very overkill. – Antoine Laps Apr 02 '22 at 06:09