Muzze77

Energy Storange Display 3x3

Sep 22nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.17 KB | None | 0 0
  1. shell.run("clear")
  2. mon = peripheral.wrap("back")
  3. os.loadAPI("ocs/apis/sensor")
  4. sen = sensor.wrap("top")
  5. mon.clear()
  6. sTime = 1
  7. rs.setOutput("front",true)
  8. gx,gy = mon.getSize()
  9. function cbut(x,y,text,bcol,tcol)
  10. if bcol == nil then
  11.   bcol = colors.black
  12. end
  13. if tcol == nil then
  14.   tcol = colors.white
  15. end
  16.   mon.setBackgroundColor(bcol)
  17.   mon.setTextColor(tcol)
  18.   mon.setCursorPos(x,y)
  19.   mon.write(text)
  20.   mon.setBackgroundColor(colors.black)
  21.   mon.setTextColor(colors.white)
  22.  
  23. end
  24. mon.setTextScale(0.5)
  25. while true do
  26. shell.run("clear")
  27. tab = {}
  28. n = 0
  29. s = sen.getTargets()
  30.  
  31. for v, k in pairs(s) do
  32.   if k.Name == "MFSU" then
  33.     s1 = sen.getTargetDetails(v)
  34.     tab[n] = {}
  35.     tab[n]["Stored"] = s1.Stored
  36.     tab[n]["Capacity"] = math.floor(s1.Capacity)
  37.     tab[n]["Percent"] = math.floor(100 / s1.Capacity * s1.Stored,0)
  38.     n = n +1
  39.  
  40.   end
  41.  
  42. end
  43.   mon.clear()
  44.   print(#tab .. " MFSU's loaded")
  45.   cbut(1,1,"ID")
  46.   cbut(10,1,"Stored")
  47.   cbut(22,1,"Capacity")
  48.   cbut(33,1,"Percent")
  49.  
  50.   g = 0
  51.   a = 0
  52. for i = 0 , #tab,1 do
  53.   g = g + tab[i]["Capacity"]
  54.   a = a + tab[i]["Stored"]
  55.  
  56.   if tab[i]["Percent"] == 100 then
  57.     ttcol = colors.green
  58.   elseif tab[i]["Percent"] < 100 and tab[i]["Percent"] > 50 then
  59.     ttcol = colors.orange
  60.   elseif tab[i]["Percent"] < 50 then
  61.     ttcol = colors.red
  62.    
  63.   end
  64.   cbut(1,i+3,string.format("%d",i+1),colors.black,ttcol)
  65.   cbut(10,i+3,string.format("%d",tab[i]["Stored"]),colors.black,ttcol)
  66.   cbut(20,i+3,"/", colors.black,ttcol)
  67.   cbut(22,i+3,string.format("%d",tab[i]["Capacity"]),colors.black,ttcol)
  68.   cbut(33,i+3,string.format("%d",tab[i]["Percent"]),colors.black,ttcol)
  69.  
  70.   if tab[i]["Percent"] < 100 then
  71.   cbut(35,i+3,"  %",colors.black,ttcol)
  72.   else
  73.  
  74.  
  75.   cbut(36,i+3," %",colors.black,ttcol)
  76.   end
  77.  
  78.  
  79.  
  80. end
  81. i = 100 / g * a
  82. cbut(1,gy-1,"Sum:")
  83. cbut(10,gy-1,string.format("%d",a))
  84. cbut(20,gy-1,"/")
  85. cbut(22,gy-1,string.format("%d",g))
  86. cbut(33,gy-1,string.format("%d",i))
  87. if i < 100 then
  88.   cbut(35,gy-1,"  %")
  89.  else
  90.   cbut(36,gy-1," %")
  91.  end
  92.  
  93.  
  94.  
  95.  
  96. if i > 90 and i <= 100 then
  97.   rs.setOutput("front",false)
  98. elseif i < 90 then
  99.   rs.setOutput("front",true)
  100.   end
  101. sleep(sTime)
  102. end
Add Comment
Please, Sign In to add comment