Page 1 of 1

timer with luacontroller

PostPosted: Sat May 14, 2016 23:16
by Serh Arien
Hi, i need to get a timer with the luacontroller because i need a delay of 120 seconds and i'm afraid it lag with 120 delayer from mesecon mod

Someone prupose me this code but it's no work :
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    Interrupt(1) --executes the programm every second
    if (event.type == "on" and event.pin.name == "A") then --if signal at A
       port.b = true --start counting and show it
    elseif (event.type == "interrupt" and port.b) then
       if (not mem.counter) then
         mem.counter = 0 --init
       end
       if (mem.counter == 120) then --if reaching 120 seconds
          port.b = false   --stop counter
          port.c = true     --send final signal
       else
          mem.counter = mem.counter + 1 --count up
       end
    end


Does someone know more than me about codding and can tell me the right code ( if it's possible)

Thank you

Re: timer with luacontroller

PostPosted: Mon May 16, 2016 07:16
by Krock
Serh Arien wrote:Hi, i need to get a timer with the luacontroller because i need a delay of 120 seconds and i'm afraid it lag with 120 delayer from mesecon mod

Try using minetest.after()

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
if (event.type == "on" and event.pin.name == "A") then --if signal at A
   if not mem.counting then
      mem.counting = true

      minetest.after(120, function()
         port.c = true
         mem.counting = false
      end)
   end
end

Re: timer with luacontroller

PostPosted: Mon May 16, 2016 15:23
by Serh Arien
Krock wrote:
Serh Arien wrote:Hi, i need to get a timer with the luacontroller because i need a delay of 120 seconds and i'm afraid it lag with 120 delayer from mesecon mod

Try using minetest.after()

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
if (event.type == "on" and event.pin.name == "A") then --if signal at A
   if not mem.counting then
      mem.counting = true

      minetest.after(120, function()
         port.c = true
         mem.counting = false
      end)
   end
end


Meaning ? Have i to change something on the code? Add or delete things

Re: timer with luacontroller

PostPosted: Mon May 16, 2016 15:34
by Krock
Serh Arien wrote:Meaning ? Have i to change something on the code? Add or delete things

Use that code as a replacement of what you posted for your luacontroller. If you don't want to wait two minutes, simply decrease the time delay argument of the minetest.after function from 120 to 10. Hopefully it works.

EDIT: port.c won't be turned off again after the delay. You need to extend the code to turn it off after one second or more.

Re: timer with luacontroller

PostPosted: Mon May 16, 2016 16:12
by yyt16384
Krock wrote:
Serh Arien wrote:Hi, i need to get a timer with the luacontroller because i need a delay of 120 seconds and i'm afraid it lag with 120 delayer from mesecon mod

Try using minetest.after()

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
if (event.type == "on" and event.pin.name == "A") then --if signal at A
   if not mem.counting then
      mem.counting = true

      minetest.after(120, function()
         port.c = true
         mem.counting = false
      end)
   end
end


I don't think you can use minetest.after in luacontrollers.

Re: timer with luacontroller

PostPosted: Mon May 16, 2016 19:16
by Serh Arien
Krock wrote:
Serh Arien wrote:Meaning ? Have i to change something on the code? Add or delete things

Use that code as a replacement of what you posted for your luacontroller. If you don't want to wait two minutes, simply decrease the time delay argument of the minetest.after function from 120 to 10. Hopefully it works.

EDIT: port.c won't be turned off again after the delay. You need to extend the code to turn it off after one second or more.


It's no working, i think the port a is not open because there is no light on it
How can i fix it ?

I know, this is a mesecon website where it's explain but codding and me = level -100000 :D

Re: timer with luacontroller

PostPosted: Mon May 16, 2016 19:40
by cheapie
This will make the LuaC act like a delayer with any length you want. Input is pin A and output is C, change the first line to adjust the time.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local time = 120
if (event.type == "on" or event.type == "off") and event.pin.name == "A" then
   if event.type == "on" then
      interrupt(time,"on")
   elseif event.type == "off" then
      interrupt(time,"off")
   end
elseif event.type == "interrupt" then
   if event.iid == "on" then
      port.c = true
   elseif event.iid == "off" then
      port.c = false
   end
end

Re: timer with luacontroller

PostPosted: Mon May 16, 2016 20:02
by Serh Arien
cheapie wrote:This will make the LuaC act like a delayer with any length you want. Input is pin A and output is C, change the first line to adjust the time.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local time = 120
if (event.type == "on" or event.type == "off") and event.pin.name == "A" then
   if event.type == "on" then
      interrupt(time,"on")
   elseif event.type == "off" then
      interrupt(time,"off")
   end
elseif event.type == "interrupt" then
   if event.iid == "on" then
      port.c = true
   elseif event.iid == "off" then
      port.c = false
   end
end


OMG it's work ! Thank you, you helped me more than you think