论武天地论坛

 找回密码
 立即注册
搜索
查看: 3783|回复: 0

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

[复制链接]

58

主题

58

帖子

244

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
244
发表于 2020-10-11 16:48:11 | 显示全部楼层 |阅读模式



延时

sys.wait(5000) --延时5S
延时函数一般配合任务使用
819239-20201011050751070-492605855.png


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


819239-20201011050901469-1244437199.png


一次性定时器
819239-20201011051131303-2116798038.png



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


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


程序启动延时5S后打印
819239-20201011051232214-1246352302.png




循环定时器
819239-20201011051459442-1422585121.png


-- 循环定时器
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")


819239-20201011051557550-158774659.png



copycode.gif
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|论武天地论坛

GMT+8, 2024-3-29 20:03 , Processed in 0.080690 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表