Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function relay_left(relay, relay_table)
- relay_table[relay].setOutput("left", true)
- os.sleep(0.1)
- relay_table[relay].setOutput("left", false)
- end
- local function relay_top(relay,relay_table)
- relay_table[relay].setOutput("top", true)
- os.sleep(0.1)
- relay_table[relay].setOutput("top", false)
- end
- local function relay_right(relay,relay_table)
- relay_table[relay].setOutput("right", true)
- os.sleep(0.1)
- relay_table[relay].setOutput("right", false)
- end
- local raw_relays = { peripheral.find("redstone_relay")}
- local relays = {}
- local sides = {top = true, bottom = true, left = true, right = true, front = true, back = true}
- for _, relay in ipairs(raw_relays) do
- local name = peripheral.getName(relay)
- if not sides[name] then
- table.insert(relays, relay)
- end
- end
- table.sort(relays, function(a,b)
- local nameA = peripheral.getName(a)
- local nameB = peripheral.getName(b)
- local idA = tonumber(nameA:match("%d+")) or 0
- local idB = tonumber(nameB:match("%d+")) or 0
- return idA < idB
- end)
- local events = {
- function() relay_left(1, relays) end,
- function() relay_top(1, relays) end,
- function() relay_right(1, relays) end,
- function() relay_left(2, relays) end,
- function() relay_top(2, relays) end,
- function() relay_right(2, relays) end
- }
- local timing = {1,2,5,3,1,2}
- local function run_show(start_point)
- for i = start_point, #timing do
- events[i]()
- os.sleep(timing[i])
- end
- end
- local function test_relays()
- for i, relay in ipairs(relays) do
- local name = peripheral.getName(relay)
- if name ~= "back" then
- relay.setOutput("top", true)
- os.sleep(0.1)
- relay.setOutput("top", false)
- relay.setOutput("left", true)
- os.sleep(0.1)
- relay.setOutput("left", false)
- relay.setOutput("right", true)
- os.sleep(0.1)
- relay.setOutput("right", false)
- end
- end
- end
- local function print_relays()
- for i, relay in ipairs(relays) do
- print(string.format("[%d] %s", i, peripheral.getName(relay)))
- end
- end
- local function main()
- print("Show controller ready.")
- print("Waiting for signal...")
- while true do
- -- Wait until the front receives a redstone signal
- while not redstone.getInput("front") do
- os.pullEvent("redstone")
- end
- print("Signal received! Starting show...")
- run_show(1)
- print("Show finished. Resetting...")
- while redstone.getInput("front") do
- os.pullEvent("redstone")
- end
- print("Ready for next show.")
- print("Waiting for signal...")
- end
- end
- -- Start the program
- main()
Advertisement
Add Comment
Please, Sign In to add comment