Advertisement
XLT_Frank

Redstone Energy Cell Control

Apr 13th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. cell_position = "front"
  2. latch = false
  3.  
  4. cell = peripheral.wrap(cell_position)
  5.  
  6. while(true) do
  7.   capacity = 100*cell.getEnergyStored(cell_position)/cell.getMaxEnergyStored(cell_position)
  8.   capacity = math.floor(capacity)
  9.  
  10.   if (latch == false) then
  11.     if (capacity <= 100 and capacity >= 80) then
  12.       redstone.setBundledOutput("back", 0)
  13.     elseif (capacity < 80 and capacity >= 60) then
  14.       redstone.setBundledOutput("back", colors.white)
  15.     elseif (capacity < 60 and capacity >= 40) then
  16.       redstone.setBundledOutput("back", colors.combine(colors.white,colors.orange))
  17.     elseif (capacity < 40 and capacity >= 20) then
  18.       redstone.setBundledOutput("back", colors.combine(colors.white,colors.orange,colors.magenta))
  19.     elseif (capacity < 20 and capacity >= 0) then
  20.       redstone.setBundledOutput("back", colors.combine(colors.white,colors.orange,colors.magenta,colors.lightBlue))
  21.       latch = true
  22.     end
  23.   elseif (latch == true) then
  24.     if (capacity <= 99) then
  25.       redstone.setBundledOutput("back", colors.combine(colors.white,colors.orange,colors.magenta,colors.lightBlue))
  26.     elseif (capacity > 99) then
  27.     latch = false
  28.     end
  29.   end
  30.   stages_active = redstone.getBundledOutput("back")
  31.   print("Capacity: "..capacity.."% / Stages Active: "..stages_active)
  32.  
  33.   os.sleep(5)
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement