有什么方法可以运行两个循环?

发布于 2025-01-18 10:35:49 字数 370 浏览 3 评论 0 原文

在Arduino的I2C LCD的第二行中滚动文本时,我无法执行闪烁的文本。

我尝试创建和命名两个循环,但它正在执行一个任务,然后是另一个任务。

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

}

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自我难过 2025-01-25 10:35:49

您只需编写所有代码,而不会阻塞延迟。我可以建议你使用 millis 。返回自启动以来的毫秒数的函数。

尝试类似的东西:(打印空闲内存所有 10 秒的函数)

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());
     }
     // ...
}

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());
     }
     // ...
}
Saygoodbye 2025-01-25 10:35:49

我认为同时执行多个过程的唯一方法是使用多线程
检查这个项目,以LCD的示例演示

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文