Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables
- local monitor = peripheral.find("monitor")
- local running = true
- local paused = true -- Initially paused
- local direction = "bottom"
- local delay = 2
- local cycles = 0 -- Counter for the number of cycles run
- local targetCycles = nil -- Target number of cycles before shutdown (optional)
- -- Function to print current status
- local function printStatus()
- print("------ STATUS ------")
- print("DIRECTION: " .. string.upper(direction))
- print(string.format("DELAY: %.2f SECONDS", delay)) -- Display delay with 2 decimal places
- print("TARGET: " .. (targetCycles and tostring(math.floor(targetCycles)) or "UNDEFINED")) -- Remove decimal places
- print("CYCLES: " .. tostring(math.floor(cycles))) -- Remove decimal places
- print("--------------------")
- end
- local function printStatusMonitor()
- monitor.setTextColor(colors.green) -- Set the text color to green
- local idleMessage1 = " - IDLE-"
- local idleMessage2 = " -IDLE -"
- local runningMessage = " ---[ RUNNING ]---"
- local frame = 1
- while true do -- Keep the loop running to switch between animations
- monitor.clear()
- monitor.setCursorPos(1, 1)
- if targetCycles then
- monitor.write("CYCLES:")
- monitor.setCursorPos(1, 2)
- monitor.write(tostring(math.floor(cycles)) .. "/" .. tostring(math.floor(targetCycles))) -- Remove decimal places
- else
- monitor.write("CYCLES:")
- monitor.setCursorPos(1, 2)
- monitor.write(tostring(math.floor(cycles))) -- Remove decimal places
- end
- monitor.setCursorPos(1, 3)
- if paused then
- -- Idle Animation
- if frame == 1 then
- monitor.write(" \\ ")
- monitor.setCursorPos(1, 4)
- monitor.write(idleMessage1)
- monitor.setCursorPos(1, 5)
- monitor.write(" \\ ")
- elseif frame == 2 then
- monitor.write(" | ")
- monitor.setCursorPos(1, 4)
- monitor.write(idleMessage1)
- monitor.setCursorPos(1, 5)
- monitor.write(" | ")
- elseif frame == 3 then
- monitor.write(" / ")
- monitor.setCursorPos(1, 4)
- monitor.write(idleMessage2)
- monitor.setCursorPos(1, 5)
- monitor.write(" / ")
- elseif frame == 4 then
- monitor.write(" | ")
- monitor.setCursorPos(1, 4)
- monitor.write(idleMessage2)
- monitor.setCursorPos(1, 5)
- monitor.write(" | ")
- end
- else
- monitor.setCursorPos(1, 4)
- -- Animation for Smelt Mode (Scrolling Message)
- local displayMessage = runningMessage:sub(frame, frame + 15)
- monitor.write(displayMessage)
- frame = frame + 1
- if frame > #runningMessage then
- frame = 1
- end
- end
- -- Increment the frame and loop back to the start if necessary
- frame = frame + 1
- if paused and frame > 4 then
- frame = 1
- end
- sleep(0.2) -- Wait for 0.2 seconds
- end
- end
- -- Functions for Command Handling
- function handleStartCommand()
- write("Enter the target number of cycles to run (or press Enter to skip): ")
- targetCycles = tonumber(read()) or targetCycles
- paused = false
- print("running initiated. The auto boiler is now running.")
- printStatus()
- end
- function handlePauseCommand()
- paused = true
- print("running paused. The auto boiler is now idle.")
- printStatus()
- end
- function handleResumeCommand()
- paused = false
- print("running resumed. The auto boiler is now running.")
- printStatus()
- end
- function handleExitCommand()
- running = false
- print("Exiting program. Goodbye!")
- end
- function handleStopCommand()
- paused = true
- cycles = 0
- print("running stopped. The auto boiler is now idle.")
- printStatus()
- end
- function handleDirectionCommand()
- write("Enter the direction to output the redstone signal (top, bottom, left, right, front, back): ")
- local newDirection = read()
- if newDirection == "top" or newDirection == "bottom" or newDirection == "left" or newDirection == "right" or newDirection == "front" or newDirection == "back" then
- direction = newDirection
- print("Direction changed to " .. string.upper(direction) .. ".")
- printStatus()
- else
- print("INVALID DIRECTION. PLEASE TRY AGAIN.")
- end
- end
- function handleDelayCommand()
- write("Enter the delay in seconds between each redstone signal (or press Enter to skip): ")
- local newDelay = tonumber(read())
- if newDelay then
- delay = newDelay
- print("Delay changed to " .. delay .. " seconds.")
- printStatus()
- else
- print("INVALID DELAY. PLEASE TRY AGAIN.")
- end
- end
- function handleTargetCommand()
- write("Enter the target number of cycles to smelt (or press Enter to skip): ")
- local newTarget = tonumber(read())
- if newTarget then
- targetCycles = newTarget
- print("Target cycles changed to " .. targetCycles .. ".")
- printStatus()
- else
- print("INVALID TARGET. PLEASE TRY AGAIN.")
- end
- end
- function handleCyclesCommand()
- print("Cycles: " .. cycles)
- end
- function handleHelpCommand()
- print("AVAILABLE COMMANDS:")
- print(" START - OPTIONAL SET TARGET: <start 10>")
- print(" PAUSE - SUSPEND BOILER")
- print(" RESUME - REACTIVATE BOILER")
- print(" STOP - RESET CYCLES")
- print(" STATUS - DISPLAY CURRENT STATUS")
- print(" DIRECTION - MODIFY SIGNAL DIRECTION")
- print(" DELAY - ADJUST TIME BETWEEN SMELTS")
- print(" TARGET - SET TARGET NUMBER OF CYCLES")
- print(" CYCLES - DISPLAY CYCLE NUMBER")
- print(" HELP - DISPLAY THIS HELP MESSAGE")
- print(" EXIT - TERMINATE PROGRAM")
- end
- -- Function to handle redstone signal
- local function redstoneSignal()
- while running do
- if not paused then
- redstone.setOutput(direction, true)
- sleep(delay)
- redstone.setOutput(direction, false)
- sleep(delay)
- cycles = cycles + 1 -- Increment the cycle counter
- -- Check if target cycles reached
- if targetCycles and cycles >= targetCycles then
- print("TARGET cycles REACHED. TERMINATING PROGRAM.")
- running = false
- end
- else
- sleep(1) -- Wait a bit before checking pause status again
- end
- end
- end
- -- Welcome message
- print("==========================================")
- print("= WELCOME TO THE AUTOBOILER CLOCK v1.0 =")
- print("= RARE Corp. =")
- print("==========================================")
- print("This program operates like a redstone clock.")
- print("Type 'start' to begin running.")
- print("Type 'pause' to pause the boiler.")
- print("Type 'help' to see all other commands.")
- print("------------------------------------------")
- printStatus()
- print("------------------------------------------")
- -- Start the redstone signal function in a separate thread
- parallel.waitForAny(
- redstoneSignal,
- printStatusMonitor,
- function()
- while running do
- write("ENTER COMMAND: ")
- local command = read()
- -- Command Handling
- if command == "start" then handleStartCommand()
- elseif command == "pause" then handlePauseCommand()
- elseif command == "resume" then handleResumeCommand()
- elseif command == "stop" then handleStopCommand()
- elseif command == "status" then printStatus()
- elseif command == "direction" then handleDirectionCommand()
- elseif command == "delay" then handleDelayCommand()
- elseif command == "target" then handleTargetCommand()
- elseif command == "cycles" then handleCyclesCommand()
- elseif command == "exit" then handleExitCommand()
- elseif command == "help" then handleHelpCommand()
- else print("UNKNOWN COMMAND. PLEASE TRY AGAIN.") end
- end
- end
- )
- -- Clean up and ensure redstone signal is off
- redstone.setOutput(direction, false)
- monitor.clear()
- print("System shutting down. Thank you for using the Auto Boiler Clock v1.0.")
- print("Total cycles run this session: " .. cycles) -- Display the final cycle count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement