Advertisement
Paullie

Energycell Reader

Jun 30th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. A very simple program, Not sure if it's what you wanted. You do require the newest version of openPeripheral for this to work.
  2. redstoneSide = "right" -- Where to output redstone signal
  3. redstoneState = true -- What state to put the redstone in when the chosen limit hits
  4. energyPercent = 90 -- what percentage to react on  
  5. reCheckTimer = 5 -- How many seconds to wait before it checks again
  6. EnergyCellSide = "left" -- Which side of the computer the energy cell is on
  7.  
  8. enCell = peripheral.wrap(EnergyCellSide)
  9.  
  10. function getEnergy()
  11.    return enCell.getEnergyStored("unknown")
  12. end
  13.  
  14. function getMaxEnergy()
  15.    return enCell.getMaxEnergyStored("unkown")
  16. end
  17.  
  18. function getEnergyPercent()
  19.    return math.floor(getEnergy()/getMaxEnergy()*100)
  20. end
  21.  
  22. while true do
  23.    if getEnergyPercent() >= energyPercent then
  24.        rs.setOutput(redstoneSide, redstoneState)
  25.    else
  26.        rs.setOutput(redstoneSide, not redstoneState)
  27.    end
  28.    sleep(reCheckTimer)
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement