AssortedBrunoz

yargh

Sep 7th, 2024
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. local network = peripheral.wrap("back")
  2. local cr = "redrouter_3" -- control router
  3. local resources = {}
  4. resources.logs = "redrouter_0"
  5. resources.apples = "redrouter_2"
  6. resources.sticks = "redrouter_1"
  7. local old = term
  8. local monitor = peripheral.wrap("left")
  9. term.redirect(monitor)
  10. term.clear()
  11. term.setCursorPos(1,1)
  12. term.write("starting..")
  13. os.sleep(1.5)
  14. term.clear()
  15. local threshold = 80 --percentage
  16.  
  17. function on()
  18. network.callRemote(cr, "setOutput", "back", true)
  19. end
  20.  
  21. function off()
  22. network.callRemote(cr, "setOutput", "back", false)
  23. end
  24.  
  25. function get_percent_from_redstone(amount)
  26.  
  27. return amount / 15
  28.  
  29. end
  30.  
  31. repeat
  32.  
  33. term.clear()
  34. local stay_on = false
  35.  
  36. for name, resource in pairs(resources) do
  37.  
  38. percent = get_percent_from_redstone(network.callRemote(resource, "getAnalogInput", "front")) * 100
  39.  
  40. term.write(name..": "..math.floor(percent).."%")
  41.  
  42. x, y = term.getCursorPos()
  43.  
  44. term.setCursorPos(1,y+1)
  45.  
  46. if percent < threshold then
  47. stay_on = true
  48. end
  49. end
  50.  
  51. if stay_on then
  52. on()
  53. else
  54. off()
  55. end
  56.  
  57. os.sleep(1)
  58.  
  59. term.setCursorPos(1,1)
  60.  
  61. until redstone.getInput("top")
  62.  
  63. network.callRemote(cr, "setOutput", "back", false)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
Add Comment
Please, Sign In to add comment