Advertisement
setdebarr

RFTools Endergenic Control

Oct 31st, 2020 (edited)
2,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. local e_cell = peripheral.wrap("left")
  2. local redstone_side = "right"
  3. local stored = 0
  4. local prevStored = 0
  5. local percentage = 0
  6. local status = "Idle"
  7.  
  8. local function setStored()
  9.     stored = e_cell.getEnergyStored()
  10. end
  11.  
  12. local function check()
  13.     setStored()
  14.     if (stored == 0) then
  15.         percentage = 0
  16.     else
  17.         percentage = stored / e_cell.getMaxEnergyStored()
  18.     end
  19.  
  20.     if (0.9 <= percentage) then
  21.         status = "Idle"
  22.         rs.setOutput(redstone_side, false)
  23.     elseif (0.2 >= percentage) then
  24.         status = "Generating"
  25.         rs.setOutput(redstone_side, true)
  26.     end
  27. end
  28.  
  29. local function displayStatus()
  30.     term.clear()
  31.     term.setCursorPos(1,1)
  32.     print("     Status: "..status)
  33.     if (stored == 0) then
  34.         print("Energy Cell: 0%")
  35.     else
  36.         print("Energy Cell: "..math.floor(((percentage * 100) * 100) / 100).."%")
  37.     end
  38.    
  39. end
  40.  
  41. while true do
  42.     check()
  43.     displayStatus()
  44.     prevStored = stored
  45.     os.sleep(5)
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement