zoukankan      html  css  js  c++  java
  • 2.4-Air302(NB-IOT)-基础外设-延时,定时器

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

  • 相关阅读:
    淘宝返回顶部
    混合布局
    css布局使用定位和margin
    选项卡 js操作
    ul li 好友列表
    js添加删除元素
    下拉列表的简单操作
    python笔记
    kali linux 虚拟机网卡未启动
    python 重新安装pip(python2和python3共存以及pip共存)
  • 原文地址:https://www.cnblogs.com/yangfengwu/p/13796109.html
Copyright © 2011-2022 走看看