cc-stuff/clock-chime.lua

23 lines
617 B
Lua

-- Program that sends a redstone pulse at noon and midnight
-- the side of the computer to output the pulse
local SIDE = "right"
function pulse ()
rs.setOutput(true, SIDE)
os.sleep(0.05) -- maybe sleep for a tick?
rs.setOutput(false, SIDE)
end
while true do
local timedelta = (os.time("ingame") % 12) * 60 -- all times in seconds
local sleep_amt = ((12 * 60) - timedelta) / 2 -- cut the time in half?
if timedelta < 1 then
pulse()
os.sleep(1) -- don't pulse more than once
elseif sleep_amt > 1 then
os.sleep(sleep_amt)
else
os.sleep(0.2)
end
end