Advertisement
Mojokojo69

boiler

Aug 23rd, 2023 (edited)
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. -- Variables
  2. local monitor = peripheral.find("monitor")
  3. local running = true
  4. local paused = true -- Initially paused
  5. local direction = "bottom"
  6. local delay = 2
  7. local cycles = 0 -- Counter for the number of cycles run
  8. local targetCycles = nil -- Target number of cycles before shutdown (optional)
  9.  
  10.  
  11. -- Function to print current status
  12. local function printStatus()
  13. print("------ STATUS ------")
  14. print("DIRECTION: " .. string.upper(direction))
  15. print(string.format("DELAY: %.2f SECONDS", delay)) -- Display delay with 2 decimal places
  16. print("TARGET: " .. (targetCycles and tostring(math.floor(targetCycles)) or "UNDEFINED")) -- Remove decimal places
  17. print("CYCLES: " .. tostring(math.floor(cycles))) -- Remove decimal places
  18. print("--------------------")
  19. end
  20.  
  21. local function printStatusMonitor()
  22. monitor.setTextColor(colors.green) -- Set the text color to green
  23. local idleMessage1 = " - IDLE-"
  24. local idleMessage2 = " -IDLE -"
  25. local runningMessage = " ---[ RUNNING ]---"
  26. local frame = 1
  27. while true do -- Keep the loop running to switch between animations
  28. monitor.clear()
  29. monitor.setCursorPos(1, 1)
  30. if targetCycles then
  31. monitor.write("CYCLES:")
  32. monitor.setCursorPos(1, 2)
  33. monitor.write(tostring(math.floor(cycles)) .. "/" .. tostring(math.floor(targetCycles))) -- Remove decimal places
  34. else
  35. monitor.write("CYCLES:")
  36. monitor.setCursorPos(1, 2)
  37. monitor.write(tostring(math.floor(cycles))) -- Remove decimal places
  38. end
  39.  
  40. monitor.setCursorPos(1, 3)
  41. if paused then
  42. -- Idle Animation
  43. if frame == 1 then
  44. monitor.write(" \\ ")
  45. monitor.setCursorPos(1, 4)
  46. monitor.write(idleMessage1)
  47. monitor.setCursorPos(1, 5)
  48. monitor.write(" \\ ")
  49. elseif frame == 2 then
  50. monitor.write(" | ")
  51. monitor.setCursorPos(1, 4)
  52. monitor.write(idleMessage1)
  53. monitor.setCursorPos(1, 5)
  54. monitor.write(" | ")
  55. elseif frame == 3 then
  56. monitor.write(" / ")
  57. monitor.setCursorPos(1, 4)
  58. monitor.write(idleMessage2)
  59. monitor.setCursorPos(1, 5)
  60. monitor.write(" / ")
  61. elseif frame == 4 then
  62. monitor.write(" | ")
  63. monitor.setCursorPos(1, 4)
  64. monitor.write(idleMessage2)
  65. monitor.setCursorPos(1, 5)
  66. monitor.write(" | ")
  67. end
  68. else
  69. monitor.setCursorPos(1, 4)
  70. -- Animation for Smelt Mode (Scrolling Message)
  71. local displayMessage = runningMessage:sub(frame, frame + 15)
  72. monitor.write(displayMessage)
  73. frame = frame + 1
  74. if frame > #runningMessage then
  75. frame = 1
  76. end
  77. end
  78.  
  79. -- Increment the frame and loop back to the start if necessary
  80. frame = frame + 1
  81. if paused and frame > 4 then
  82. frame = 1
  83. end
  84.  
  85. sleep(0.2) -- Wait for 0.2 seconds
  86. end
  87. end
  88.  
  89.  
  90. -- Functions for Command Handling
  91. function handleStartCommand()
  92. write("Enter the target number of cycles to run (or press Enter to skip): ")
  93. targetCycles = tonumber(read()) or targetCycles
  94. paused = false
  95. print("running initiated. The auto boiler is now running.")
  96. printStatus()
  97. end
  98.  
  99. function handlePauseCommand()
  100. paused = true
  101. print("running paused. The auto boiler is now idle.")
  102. printStatus()
  103. end
  104.  
  105. function handleResumeCommand()
  106. paused = false
  107. print("running resumed. The auto boiler is now running.")
  108. printStatus()
  109. end
  110.  
  111. function handleExitCommand()
  112. running = false
  113. print("Exiting program. Goodbye!")
  114. end
  115.  
  116. function handleStopCommand()
  117. paused = true
  118. cycles = 0
  119. print("running stopped. The auto boiler is now idle.")
  120. printStatus()
  121. end
  122.  
  123. function handleDirectionCommand()
  124. write("Enter the direction to output the redstone signal (top, bottom, left, right, front, back): ")
  125. local newDirection = read()
  126. if newDirection == "top" or newDirection == "bottom" or newDirection == "left" or newDirection == "right" or newDirection == "front" or newDirection == "back" then
  127. direction = newDirection
  128. print("Direction changed to " .. string.upper(direction) .. ".")
  129. printStatus()
  130. else
  131. print("INVALID DIRECTION. PLEASE TRY AGAIN.")
  132. end
  133. end
  134.  
  135. function handleDelayCommand()
  136. write("Enter the delay in seconds between each redstone signal (or press Enter to skip): ")
  137. local newDelay = tonumber(read())
  138. if newDelay then
  139. delay = newDelay
  140. print("Delay changed to " .. delay .. " seconds.")
  141. printStatus()
  142. else
  143. print("INVALID DELAY. PLEASE TRY AGAIN.")
  144. end
  145. end
  146.  
  147. function handleTargetCommand()
  148. write("Enter the target number of cycles to smelt (or press Enter to skip): ")
  149. local newTarget = tonumber(read())
  150. if newTarget then
  151. targetCycles = newTarget
  152. print("Target cycles changed to " .. targetCycles .. ".")
  153. printStatus()
  154. else
  155. print("INVALID TARGET. PLEASE TRY AGAIN.")
  156. end
  157. end
  158.  
  159. function handleCyclesCommand()
  160. print("Cycles: " .. cycles)
  161. end
  162.  
  163. function handleHelpCommand()
  164. print("AVAILABLE COMMANDS:")
  165. print(" START - OPTIONAL SET TARGET: <start 10>")
  166. print(" PAUSE - SUSPEND BOILER")
  167. print(" RESUME - REACTIVATE BOILER")
  168. print(" STOP - RESET CYCLES")
  169. print(" STATUS - DISPLAY CURRENT STATUS")
  170. print(" DIRECTION - MODIFY SIGNAL DIRECTION")
  171. print(" DELAY - ADJUST TIME BETWEEN SMELTS")
  172. print(" TARGET - SET TARGET NUMBER OF CYCLES")
  173. print(" CYCLES - DISPLAY CYCLE NUMBER")
  174. print(" HELP - DISPLAY THIS HELP MESSAGE")
  175. print(" EXIT - TERMINATE PROGRAM")
  176. end
  177.  
  178. -- Function to handle redstone signal
  179. local function redstoneSignal()
  180. while running do
  181. if not paused then
  182. redstone.setOutput(direction, true)
  183. sleep(delay)
  184. redstone.setOutput(direction, false)
  185. sleep(delay)
  186. cycles = cycles + 1 -- Increment the cycle counter
  187. -- Check if target cycles reached
  188. if targetCycles and cycles >= targetCycles then
  189. print("TARGET cycles REACHED. TERMINATING PROGRAM.")
  190. running = false
  191. end
  192. else
  193. sleep(1) -- Wait a bit before checking pause status again
  194. end
  195. end
  196. end
  197.  
  198. -- Welcome message
  199. print("==========================================")
  200. print("= WELCOME TO THE AUTOBOILER CLOCK v1.0 =")
  201. print("= RARE Corp. =")
  202. print("==========================================")
  203. print("This program operates like a redstone clock.")
  204. print("Type 'start' to begin running.")
  205. print("Type 'pause' to pause the boiler.")
  206. print("Type 'help' to see all other commands.")
  207. print("------------------------------------------")
  208. printStatus()
  209. print("------------------------------------------")
  210.  
  211. -- Start the redstone signal function in a separate thread
  212. parallel.waitForAny(
  213. redstoneSignal,
  214. printStatusMonitor,
  215. function()
  216. while running do
  217. write("ENTER COMMAND: ")
  218. local command = read()
  219.  
  220. -- Command Handling
  221. if command == "start" then handleStartCommand()
  222. elseif command == "pause" then handlePauseCommand()
  223. elseif command == "resume" then handleResumeCommand()
  224. elseif command == "stop" then handleStopCommand()
  225. elseif command == "status" then printStatus()
  226. elseif command == "direction" then handleDirectionCommand()
  227. elseif command == "delay" then handleDelayCommand()
  228. elseif command == "target" then handleTargetCommand()
  229. elseif command == "cycles" then handleCyclesCommand()
  230. elseif command == "exit" then handleExitCommand()
  231. elseif command == "help" then handleHelpCommand()
  232. else print("UNKNOWN COMMAND. PLEASE TRY AGAIN.") end
  233. end
  234. end
  235. )
  236.  
  237. -- Clean up and ensure redstone signal is off
  238. redstone.setOutput(direction, false)
  239. monitor.clear()
  240. print("System shutting down. Thank you for using the Auto Boiler Clock v1.0.")
  241. print("Total cycles run this session: " .. cycles) -- Display the final cycle count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement