Difference between revisions of "Simple lua controller blinker"

From Pandorabox
Jump to navigation Jump to search
(Created page with "A simple lua-controller based blinker Toggles the port '''A''' every 2 seconds === Simple version === <syntaxhighlight lang="Lua"> interrupt(2) port.a = not port.a </syntaxh...")
 
 
Line 26: Line 26:
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
'''NOTE''': be aware of the per-mapblock mesecons restrictions if you intend to decrease the interval, see [[Mesecons speed advices]]
  
  
 
[[Category:Lua controller]]
 
[[Category:Lua controller]]

Latest revision as of 14:17, 19 April 2021

A simple lua-controller based blinker

Toggles the port A every 2 seconds

Simple version

interrupt(2)
port.a = not port.a

Verbose version

This example shows all the various events in play:

if event.type == "program" then
 -- initially triggered by the "program" button on the LuaC
 -- start the interrupt timer
 interrupt(2)
end

if event.type == "interrupt" then
 -- triggered by the expiration of the interrupt timer
 port.a = not port.a
 -- trigger again in a few seconds
 interrupt(2)
end


NOTE: be aware of the per-mapblock mesecons restrictions if you intend to decrease the interval, see Mesecons speed advices