Advertisement
Sibmer

TE cell script

Dec 14th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. -- For 1.12.2 versions of Thermal Expansion and EnderIO
  2. -- Monitors TE5 Energy cells and EnderIO capacitor banks and output redstone signals once energy storage drops below set limits.
  3. -- Will automatically detect direction of adjacent storage device and (optional) Advanced Monitors. If chosen, monitor format should be 1 high and 2 wide. Now also with wired modem support for both storage and monitors. Directly adjacent devices will take priority over any wired devices.
  4. -- Redstone signal for the engines will be output out the back of the computer.
  5. --More details: http://forum.feed-the-beast.com/threads/rhns-1-6-monster-build-journal-and-guide-collection.42664/page-15#post-718973
  6.  
  7.  
  8. local upper = 14 --Upper limit for computer to stop transmitting redstone signal.
  9. local lower = 7 --Lower limit for computer to start transmitting redstone signal.
  10. local outSide = "back"
  11.  
  12. --Device detection
  13. isError=0
  14.  
  15. function detectDevice(DeviceName)
  16. DeviceSide="none"
  17. for k,v in pairs(redstone.getSides()) do
  18. if peripheral.getType(v) and string.find(peripheral.getType(v), DeviceName) then
  19. --if peripheral.getType(v)==DeviceName then
  20. --if string.find(peripheral.getType(v), DeviceName) then
  21. DeviceSide = v
  22. break
  23. --end
  24. end
  25. end
  26. return(DeviceSide)
  27. end
  28.  
  29.  
  30. cell="none"
  31. monitor="none"
  32. local peripheralList = peripheral.getNames()
  33.  
  34. CellSide="right"
  35.  
  36. MonitorSide=detectDevice("monitor")
  37.  
  38. if MonitorSide~="none" then
  39. monitor=peripheral.wrap(MonitorSide)
  40. print ("Monitor on the " .. MonitorSide .. " connected.")
  41. else
  42. for Index = 1, #peripheralList do
  43. if string.find(peripheralList[Index], "monitor") then
  44. monitor=peripheral.wrap(peripheralList[Index])
  45. print ("Monitor on wired modem: "..peripheralList[Index].." connected.")
  46. end
  47. end --for
  48. if monitor == "none" then
  49. print ("Warning - No Monitor attached, continuing without.")
  50. end
  51. end
  52.  
  53. --Main code
  54. redstone.setOutput(outSide, false) --Defaulting to off
  55.  
  56. --If monitor is attached, write data on monitor
  57. if monitor ~= "none" then
  58. monitor.clear()
  59. monitor.setBackgroundColour((colours.grey))
  60. monitor.setCursorPos(1,3)
  61. monitor.write(" ON ")
  62. monitor.setBackgroundColour((colours.black))
  63. end
  64.  
  65. --Main loop
  66. while true do
  67. --Compute ratio
  68. fill = redstone.getAnalogInput(CellSide)
  69.  
  70. if fill >= upper then
  71. --energylevel is over upper level, turning redstone signal on
  72. redstone.setOutput(outSide, true)
  73.  
  74. if monitor ~= "none" then
  75. monitor.setBackgroundColour((colours.grey))
  76. monitor.setCursorPos(1,3)
  77. monitor.write(" OFF ")
  78. monitor.setBackgroundColour((colours.black))
  79. end
  80.  
  81. elseif fill <= lower then
  82. --energy level is below lower limit, turning redstone signal off
  83. redstone.setOutput(outSide, false)
  84.  
  85. if monitor ~= "none" then
  86. monitor.setBackgroundColour((colours.grey))
  87. monitor.setCursorPos(1,3)
  88. monitor.write(" ON ")
  89. monitor.setBackgroundColour((colours.black))
  90. end
  91. end
  92.  
  93.  
  94. sleep(1)
  95. end --while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement