LuatOS
直播中

工程认知教育中心的硬件小屋

5年用户 22经验值
擅长:模拟技术
私信 关注
[经验]

【合宙Air105开发板试用体验】Air105定时器以及LuaTask框架的使用

一.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灯的循环点亮
三.实验代码

  1. PROJECT = 'helloworld'
  2. VERSION = '1.0.0'

  3. -- 引入必要的库文件(lua编写), 内部库不需要require
  4. local sys = require 'sys'
  5. log.info('main', 'hello world')
  6. gpio.setup(62,0,gpio.PULLDOWN)
  7. gpio.setup(63,0,gpio.PULLDOWN)
  8. gpio.set(62,0)
  9. gpio.set(63,0)
  10. print(_VERSION)

  11. sys.timerLoopStart(function()
  12.         print('hi, LuatOS')
  13. end, 3000)
  14. local a=1

  15. sys.taskInit(function()
  16.        
  17.         while true do
  18.         if a==1 then
  19.                 sys.timerStart(function() gpio.set(62,1) a=0 end,500)
  20.         end
  21.     if a==0 then
  22.                 sys.timerStart(function() gpio.set(62,0) a=1 end,1000)

  23.         end       
  24.     sys.wait(1000)
  25.     end
  26.        
  27.        
  28.        
  29. end)

  30. local b=1
  31. sys.timerLoopStart(function ()
  32.   if b==1 then
  33.         gpio.set(63,1)
  34.         b=0
  35.    else
  36.         gpio.set(63,0)
  37.     b=1
  38.    end
  39. end,500)

  40. sys.run()




更多回帖

发帖
×
20
完善资料,
赚取积分