Advertisement
rhn

Energy cell power monitor

rhn
Jul 30th, 2014
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. --Monitors power storage devices such as TE3 Energy cells and output redstone signals once energy storage drops below set limits.
  2. --Building guide(looking at the front of the devices):
  3. -- MM
  4. -- EC
  5.  
  6. -- M: Monitor, E: Energy storage device, C: Computer
  7. -- Redstone signal for the engines will be output out the back of the computer.
  8.  
  9. -- More details: http://forum.feed-the-beast.com/threads/rhns-1-6-monster-build-journal-and-guide-collection.42664/page-15#post-718973
  10.  
  11.  
  12. local monitor = peripheral.wrap("top")
  13. local cell = peripheral.wrap("left")
  14. local upper = 0.90 --Upper limit for computer to stop transmitting redstone signal. 0.90=90% full.
  15. local lower = 0.10 --Lower limit for computer to start transmitting redstone signal.
  16.  
  17.  
  18.  
  19. redstone.setOutput("back", false) --Defaulting to off
  20.  
  21.     monitor.clear()
  22.     monitor.setBackgroundColour((colours.grey))
  23.     monitor.setCursorPos(1,4)
  24.     monitor.write(" ON ")
  25.     monitor.setBackgroundColour((colours.green))
  26.     monitor.setCursorPos(5,4)
  27.     monitor.write(" OFF ")
  28.     monitor.setBackgroundColour((colours.black))
  29.  
  30.  
  31. while true do
  32.     eNow = cell.getEnergyStored("left")
  33.     eMax = cell.getMaxEnergyStored("left")
  34.  
  35.     fill = (eNow / eMax)
  36.  
  37.  
  38.     monitor.setCursorPos(11,2)
  39.     monitor.write("Storage:")
  40.     monitor.setCursorPos(11,3)
  41.     monitor.write(eNow)
  42.     monitor.setCursorPos(11,4)
  43.     monitor.write("Of:")
  44.     monitor.setCursorPos(11,5)
  45.     monitor.write(eMax)
  46.  
  47.     monitor.setCursorPos(1,2)
  48.     monitor.write("Engines:")
  49.  
  50.  
  51.     if fill > upper then
  52.         --energylevel is over upper level, turning redstone signal off
  53.         redstone.setOutput("back", false)
  54.         monitor.setBackgroundColour((colours.grey))
  55.         monitor.setCursorPos(1,4)
  56.         monitor.write(" ON ")
  57.         monitor.setBackgroundColour((colours.green))
  58.         monitor.setCursorPos(5,4)
  59.         monitor.write(" OFF ")
  60.         monitor.setBackgroundColour((colours.black))
  61.  
  62.     elseif fill < lower then
  63.         --energy level is below lower limit, turning redstone signal on
  64.         redstone.setOutput("back", true)
  65.         monitor.setBackgroundColour((colours.green))
  66.         monitor.setCursorPos(1,4)
  67.         monitor.write(" ON ")
  68.         monitor.setBackgroundColour((colours.grey))
  69.         monitor.setCursorPos(5,4)
  70.         monitor.write(" OFF ")
  71.         monitor.setBackgroundColour((colours.black))
  72.     end
  73.  
  74.    
  75.     sleep(1)
  76. end --while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement