Advertisement
Guest User

energy

a guest
Sep 21st, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.02 KB | None | 0 0
  1. redstoneSide   = "right" -- Where to output redstone signal
  2. redstoneState  = true -- What state to put the redstone in when the chosen limit hits
  3. energyPercent  = 10 -- what percentage to react on  
  4. reCheckTimer   = 5 -- How many seconds to wait before it checks again
  5. EnergyCellSide = "left" -- Which side of the computer the energy cell is on
  6.  
  7. enCell = peripheral.wrap(EnergyCellSide)
  8. mon = peripheral.wrap("top")
  9.  
  10. function getEnergy()
  11.   return enCell.getEnergyStored("unknown")
  12. end
  13.  
  14. function getMaxEnergy()
  15.   return enCell.getMaxEnergyStored("unknown")
  16. end
  17.  
  18. function getEnergyPercent()
  19.   return math.floor(getEnergy()/getMaxEnergy()*100)
  20. end
  21.  
  22. while true do
  23.   power = getEnergyPercent()
  24.   mon.clear()
  25.   mon.setCursorPos(1,1)
  26.   mon.write(power)
  27.  
  28.   if power < energyPercent then
  29.     rs.setOutput(redstoneSide, redstoneState)
  30.     mon.setCursorPos(1,2)
  31.     mon.write("ON")
  32.   else
  33.     rs.setOutput(redstoneSide, not redstoneState)
  34.     mon.setCursorPos(1,2)
  35.     mon.write("OFF")
  36.   end
  37.   sleep(reCheckTimer)
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement