Advertisement
soulgriever

ME MFSU

Dec 12th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. --Modem Location
  2. modem = "back"
  3.  
  4. --Load Functions API
  5. function getEUStored(cell)
  6.  local count = 0
  7.  for i = 1, #cell do
  8.   count = count + cell[i].getEUStored()
  9.  end
  10.  return(count)
  11. end
  12.  
  13. function getEUCapacity(cell)
  14.  local count = 0
  15.  for i = 1, #cell do
  16.   count = count + cell[i].getEUCapacity()
  17.  end
  18.  return(count)
  19. end
  20.  
  21. function round(num, numDecimalPlaces)
  22.   local mult = 10^(numDecimalPlaces or 0)
  23.   return math.floor(num * mult + 0.5) / mult
  24. end
  25.  
  26. --Load Peripherals
  27. rednet.open(modem)
  28. --Start Program
  29.  
  30. while true do
  31.  sleep(5)
  32.  local cell = {peripheral.find("mfsu")}
  33.  stored = getEUStored(cell)
  34.  capacity = getEUCapacity(cell)
  35.  charge = stored/capacity*100
  36.  local t = {}
  37.  t[0] = "Doc,Stored,Capacity,Charge"
  38.  t[1] = stored
  39.  t[2] = capacity
  40.  t[3] = tostring(round(charge, 0))
  41.  
  42.  term.clear()
  43.  term.setCursorPos(1,1)
  44.  print(charge)
  45.  
  46.  local msg = textutils.serialize(t)
  47.  rednet.broadcast(msg, "ME-MFSU")
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement