首页 > 其他 > 详细

2.4-Air302(NB-IOT)-基础外设-延时,定时器

时间:2020-10-11 08:58:17      阅读:25      评论:0      收藏:0      [点我收藏+]

<p><iframe name="ifd" src="https://mnifdv.cn/resource/cnblogs/Learn-NB-IOT-Air302-ForLua" frameborder="0" scrolling="auto" width="100%" height="1500"></iframe></p>

 

 延时

sys.wait(5000) --延时5S

 

延时函数一般配合任务使用

技术分享图片

 

 

sys.taskInit(function()
    while 1 do
        sys.wait(500) --延时500ms
        log.info("111111111111111111111111")
    end
end)

 

 技术分享图片

 

 

一次性定时器

 技术分享图片

 

 

 

-- 一次性定时器
function OneTimer(param)
    print(param);
end

--一次性定时器: sys.timerStart
--OneTimer:回调函数
--5000:延时5S
--最后一个参数:传给回调函数的参数
sys.timerStart(OneTimer,5000,"delay 5s")

 

 程序启动延时5S后打印

 技术分享图片

 

 

 

 

循环定时器

技术分享图片

 

 

-- 循环定时器
local cnt = 0;
function LoopTimer(param)
    print(param)
    cnt = cnt+1
    if(cnt>=6) then
        cnt = 0;
        sys.timerStop(timerLoop) --停止循环定时器
        print("stop timerLoop")
    end
end

--循环定时器: sys.timerLoopStart
--LoopTimer:回调函数
--1000:延时1S
--最后一个参数:传给回调函数的参数
--timerLoop:返回的参数用于关闭定时器
timerLoop = sys.timerLoopStart(LoopTimer,1000,"this timerLoop")

 

技术分享图片

 

2.4-Air302(NB-IOT)-基础外设-延时,定时器

原文:https://www.cnblogs.com/yangfengwu/p/13796109.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!