Guest User

energyController

a guest
Aug 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. local component = require("component")
  2. local sides = require("sides")
  3. local term = require("term")
  4. local redstoneAddress = component.get("ace")
  5. local energyAddress = component.get("d78")
  6. local redstone = component.proxy(redstoneAddress)
  7. local energyCell = component.proxy(energyAddress)
  8. local energyPercent = (energyCell.getEnergyStored())/(energyCell.getMaxEnergyStored())*100
  9. local x = 0
  10. local y = 2 --Used for the power rate calculations
  11.  
  12. local function powerRate()
  13.   local a = energyCell.getEnergyStored()
  14.   local b = energyCell.getEnergyStored()
  15.   local c = (b-a)/20*y
  16.   return(c)
  17. end
  18.  
  19. term.clear()
  20. io.write("Power Controller v.1.0\n")
  21. os.sleep(1)
  22. term.clear()
  23.  
  24. while true do
  25.   if energyPercent > 75 and not (x == 1) then
  26.     x = 1
  27.     redstone.setOutput(sides.right,0)
  28.     redstone.setOutput(sides.up,0)
  29.     term.clear()
  30.     term.setCursor(1,1)
  31.     io.write("Too much power! shutting off generation.\n")
  32.   elseif (25 < energyPercent) and (energyPercent <= 75) and not (x == 2) then
  33.     x = 2
  34.     redstone.setOutput(sides.right,15)
  35.     redstone.setOutput(sides.up,0)
  36.     term.clear()
  37.     term.setCursor(1,1)
  38.     io.write("Power is stabalized")
  39.   elseif energyPercent <= 25  and not (x == 3) then
  40.     x = 3
  41.     redstone.setOutput(sides.right,15)
  42.     redstone.setOutput(sides.up,15)
  43.     term.clear()
  44.     term.setCursor(1,1)
  45.     io.write("Power is being built up!\n")
  46.   end
  47.   os.sleep(y)
  48.   term.setCursor(1,2)
  49.   term.clearLine()
  50.   io.write("RF per tick :"..powerRate())
  51. end
Advertisement
Add Comment
Please, Sign In to add comment