这个功能应该主要是用到time的库,具体的功能有:

099_Arduino延时控制_Arduino

         前面两个是计数器,后面两个是延时的函数,第一个单位是毫秒,第二个单位是微秒。前面两个已经测试过了,后面的这个或许可以这么测试:

  1. 初始化串口,打印一个数字;
  2. 使用两个延时,通过串口监控上的时间戳做一下对比。
  3. 可以测试多个时间间隔。

测试代码1:

void setup()
{
    // put your setup code here, to run once:
    Serial.begin(9600);
}

void loop()
{
    uint32_t i = 0U;
    // put your main code here, to run repeatedly:
    Serial.println("test for ms delay");
    delay(1000);
    Serial.println("test for us delay");
    for (i = 0; i < 1000; i++)
    {
        delayMicroseconds(1000);
    }
}

         测试结果:

099_Arduino延时控制_嵌入式_02

         基本上OK,for循环还是消耗了一定的时间。

测试2:延时改成500ms

void setup()
{
    // put your setup code here, to run once:
    Serial.begin(9600);
}

void loop()
{
    uint32_t i = 0U;
    // put your main code here, to run repeatedly:
    Serial.println("test for ms delay");
    delay(500);
    Serial.println("test for us delay");
    for (i = 0; i < 1000; i++)
    {
        delayMicroseconds(500);
    }
}

         测试结果:

099_Arduino延时控制_嵌入式_03

         看得出,延时还算是准确。