setdebarr

RFTools Endergenic Control

Oct 31st, 2020 (edited)
1,046
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×