一.LuaTask中定时器的介绍
sys.
timerStart(fnc,time)
fnc为回调函数,time为定时时间,在luatos中sys.timerStart定时器,只会运行一次
sys.timerLoopStart(fnc,time)
fnc为回调函数,time为定时时间,在luatos中sys.timerLoopStart定时器,会循环执行
二.实验现象及目的
通过sys.timerStart 实现D3 LED灯的循环点亮
通过 sys.timerLoopStart实现D4 LED灯的循环点亮
三.实验代码
- PROJECT = 'helloworld'
- VERSION = '1.0.0'
- -- 引入必要的库文件(lua编写), 内部库不需要require
- local sys = require 'sys'
- log.info('main', 'hello world')
- gpio.setup(62,0,gpio.PULLDOWN)
- gpio.setup(63,0,gpio.PULLDOWN)
- gpio.set(62,0)
- gpio.set(63,0)
- print(_VERSION)
- sys.timerLoopStart(function()
- print('hi, LuatOS')
- end, 3000)
- local a=1
- sys.taskInit(function()
-
- while true do
- if a==1 then
- sys.timerStart(function() gpio.set(62,1) a=0 end,500)
- end
- if a==0 then
- sys.timerStart(function() gpio.set(62,0) a=1 end,1000)
- end
- sys.wait(1000)
- end
-
-
-
- end)
- local b=1
- sys.timerLoopStart(function ()
- if b==1 then
- gpio.set(63,1)
- b=0
- else
- gpio.set(63,0)
- b=1
- end
- end,500)
- sys.run()