【问题标题】:Non-blocking timer with timer_us of the NewPing library使用 NewPing 库的 timer_us 的非阻塞定时器
【发布时间】:2017-07-11 10:18:21
【问题描述】:

我想使用 NewPing 库的 timer_us 函数,以便每秒运行一个函数而不会阻塞。我的最小示例如下所示:

// setup timer
#include <NewPing.h>
timer_us(1000, sensoring);

void setup() {
  Serial.begin(19200)
}

void loop() {}

void sensoring() {
  Serial.print("ok, it's working")
}

但它没有编译,因为:

'(' 标记之前的预期构造函数、析构函数或类型转换

我的硬件是:

Arduino:1.8.3 (Mac OS X),板:“Arduino Nano,ATmega328”

【问题讨论】:

    标签: timer arduino nonblocking


    【解决方案1】:

    两个错误:

    1. 语法是NewPing::timer_ms(。
    2. 将该行放入setup()。

    【讨论】:

    • 非常感谢!顺便说一句:有很多错误;)在这里找到工作的最小示例:// setup timer #include &lt;NewPing.h&gt; void setup() { NewPing::timer_ms(1000, sensoring); Serial.begin(19200); } void loop() {} void sensoring() { Serial.print("ok, it's working"); }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-29
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多