Simple lua controller blinker

From Pandorabox
Revision as of 14:17, 19 April 2021 by BuckarooBanzai (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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