From 5b1150452be8e8d30f981eed721f529f7b116135 Mon Sep 17 00:00:00 2001 From: erosenjo Date: Wed, 20 Aug 2025 22:26:29 -0400 Subject: [PATCH 1/2] Program for managing a clock tower bell. --- clock-chime.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 clock-chime.lua diff --git a/clock-chime.lua b/clock-chime.lua new file mode 100644 index 0000000..963dd18 --- /dev/null +++ b/clock-chime.lua @@ -0,0 +1,21 @@ +-- 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 + if timedelta < 0.2 then -- too strict? + pulse() + os.sleep(0.2) -- don't pulse more than once + else + local sleep_amt = 60 * (12 - timedelta) / 2 -- cut the time in half? + os.sleep(sleep_amt) + end +end From 8e6768532ceba7e8ffce3ceb4943e34372af937a Mon Sep 17 00:00:00 2001 From: erosenjo Date: Wed, 20 Aug 2025 22:33:02 -0400 Subject: [PATCH 2/2] Tweaked clock-chime.lua to hopefully be more robust. --- clock-chime.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/clock-chime.lua b/clock-chime.lua index 963dd18..3244ca1 100644 --- a/clock-chime.lua +++ b/clock-chime.lua @@ -10,12 +10,14 @@ function pulse () end while true do - local timedelta = os.time("ingame") % 12 - if timedelta < 0.2 then -- too strict? + 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(0.2) -- don't pulse more than once - else - local sleep_amt = 60 * (12 - timedelta) / 2 -- cut the time in half? + 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