This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
HydroBane's profile picture

Timer?

Started by HydroBane, 19 November 2012 - 03:41 AM
HydroBane #1
Posted 19 November 2012 - 04:41 AM
I'm trying to make a timer that starts and finishes on a redstone signal but don't not how to code it. Can anybody help?
remiX #2
Posted 19 November 2012 - 04:47 AM

ticks = 16
for i = 1, ticks do
    rs.setOutput("back", true)
    sleep(0.5)
    rs.setOutput("back", false)
end
billysback #3
Posted 19 November 2012 - 04:50 AM
or

local on = true
local timer = os.startTimer(0)

local interval = 0.5
while on do
   local event, p1, p2, p3 = os.pullEvent()
   if event == "timer" and p1 == timer then
	  timer = os.startTimer(interval)
   end
end
this is superior as it gives easy and working acess to events.
HydroBane #4
Posted 19 November 2012 - 05:19 AM
Thanks guys!