Article From:https://www.cnblogs.com/yangfengwu/p/9968716.html

https://www.cnblogs.com/yangfengwu/p/9968405.html

Because I see a lot of inquiries about multiple file calls, I feel that this should be said.

By the way, do you know what this is for?

 

 Have you read this article at https://www.cnblogs.com/yangfengwu/p/8965054.html?

 

 In fact, this is a few new features of Lua5. It’s designed to eliminate those complicated programs.

 I built a new test1

 

Let test call a variable in test1

    

 

 Download it in

 

 Note that this is not allowed, then use test1 to request the test file, and then call the values in the test.

      

 

 

 If you want to do this, you can actually make a file with a variable in it. Then both test and test1 can request the file and manipulate the variable.

 

Now look at the timer.

 

I’ll go straight to that.One-time timer (once executed) (without ID)

 

module(...,package.seeall)

--[[
Function name: printFunction: Print interface, all prints in this file will be prefixed with testParameter: NoneReturn value: None]]Local function print (...)_G.print ("test",...)
end

local function Timer1()
    print("One-time timer, no ID")
end

sys.timer_start(Timer1,10000)//Delay 10S to call Timer1 function

 

Download to see

 

 You don’t need to shut it down at one time, because you shut it down by yourself.

And then there’s a loop.

module(...,package.seeall)

--[[
Function name: printFunction: Print interface, all prints in this file will be prefixed with testParameter: NoneReturn value: None]]Local function print (...)_G.print ("test",...)
end

local function Timer1()
    print("One-time timer, no ID")
end

sys.timer_start(Timer1,10000)



local function Timer2()
    print("This is a circular timer, no ID")
end


sys.timer_loop_start(Timer2,2000)

 

 Now add one variable to it and add five to stop the timer.

module(...,package.seeall)

--[[
Function name: printFunction: Print interface, all prints in this file will be prefixed with testParameter: NoneReturn value: None]]Local function print (...)_G.print ("test",...)
end

local function Timer1()
    print("One-time timer, no ID")
end

sys.timer_start(Timer1,10000)


local cnt=0
local function Timer2()
    print("This is a circular timer, no ID")
cnt=cnt+1
if cnt>=5 then cnt=0 sys.timer_stop(Timer2)--Direct Fill-in Function Stop
print("This is a circular timer, no ID, stop now.EndEndSys. timer_loop_start (Timer2,
2000)

 

 

 

 Now let’s talk about IDs. Let’s have a look.

 

 

module(...,package.seeall)

--[[
Function name: printFunction: Print interface, all prints in this file will be prefixed with testParameter: NoneReturn value: None]]Local function print (...)_G.print ("test",...)
end

local function Timer1()
    print("One-time timer, no ID")
end

sys.timer_start(Timer1,10000)


local cnt=0
local function Timer2()
    print("This is a circular timer, no ID")
    cnt=cnt+1
    if  cnt>=5 then
        cnt=0
        sys.timer_stop(Timer2)--Direct Fill-in Function StopPrint ("This is a circular timer. No ID. Stop now.")
    end
end


sys.timer_loop_start(Timer2,2000)



local cnt1=0
local function Timer3()
    print("This is a circular timer with an ID.")
    cnt1=cnt1+1
    if  cnt1>=5 then
        cnt1=0
        sys.timer_stop(1)--Direct Fill-in Function StopPrint ("This is the loop timer, with ID, stop now.")
    end
end

sys.timer_loop_start(Timer3,2000,1)

 

 

 

 therefore

 

 This stops it.

 Now, every time the control lamp enters the timer, it turns on and off periodically.

local function Timer4()
    pio.pin.setval(1-pio.pin.getval(pio.P0_5),pio.P0_5)
end
sys.timer_loop_start(Timer4,2000,1)

 

1-pio.pin.getval(pio.P0_5)
pio.pin.getval(pio.P0_5)It's the read pin's high and low level state 1 - This (0 or 1) is reversed to get 1 and 0.
  

 

 Ultimately all source code

 

module(...,package.seeall)

--[[
Function name: printFunction: Print interface, all prints in this file will be prefixed with testParameter: NoneReturn value: None]]Local function print (...)_G.print ("test",...)
end

local function Timer1()
    print("One-time timer, no ID")
end
sys.timer_start(Timer1,10000)


local cnt=0
local function Timer2()
    print("This is a circular timer, no ID")
    cnt=cnt+1
    if  cnt>=5 then
        cnt=0
        sys.timer_stop(Timer2)--Direct Fill-in Function StopPrint ("This is a circular timer. No ID. Stop now.")
    end
end
sys.timer_loop_start(Timer2,2000)



local cnt1=0
local function Timer3()
    print("This is a circular timer with an ID.")
    cnt1=cnt1+1
    if  cnt1>=5 then
        cnt1=0
        sys.timer_stop(Timer3,1)
        print("This is the loop timer, with ID, stop now.")
    end
end
sys.timer_loop_start(Timer3,2000,1)



pio.pin.setdir(pio.OUTPUT,pio.P0_5)
pio.pin.setval(0,pio.P0_5)


local function Timer4()
    pio.pin.setval(1-pio.pin.getval(pio.P0_5),pio.P0_5)
end
sys.timer_loop_start(Timer4,2000,1)

 

The timer says this.

Source Link

Link: https://pan.baidu.com/s/1-SRfsKGQ7rZVvFmp1ObHWw password: p9qs

If the link of the source code of the basic course is invalid, please download it in the introduction of Taobao. Because the link is still invalid, please contact the seller. Thank you.

https://item.taobao.com/item.htm?spm=a1z10.1-c-s.w4004-18540610442.6.36a74814ZSaRsu&id=569295486025

 

 

 

https://www.cnblogs.com/yangfengwu/p/9968883.html

 

Leave a Reply

Your email address will not be published. Required fields are marked *