Advertisement
XxZajoZzO

ComputerCraft program for checking energy status

Jun 18th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.23 KB | None | 0 0
  1. --modem
  2. mod = peripheral.wrap("right")
  3. --1.Cell
  4. cell1 = peripheral.wrap("cofh_thermalexpansion_energycell_1")
  5. --2.Cell
  6. cell2 = peripheral.wrap("cofh_thermalexpansion_energycell_2")
  7. --3.Cell
  8. cell3 = peripheral.wrap("cofh_thermalexpansion_energycell_3")
  9. --4.Cell
  10. cell4 = peripheral.wrap("cofh_thermalexpansion_energycell_4")
  11. --Monitor
  12. mon = peripheral.wrap("left")
  13.  
  14. function calculate()
  15.   --1.Cell
  16.   cell1Stored = cell1.getEnergyStored("right")
  17.   cell1Full = cell1.getMaxEnergyStored("right")
  18.   cell1Precent = math.floor(100*cell1Stored/cell1Full)
  19.   cell1Bar = math.floor(cell1Precent/5)
  20.  
  21.   --2.Cell
  22.   cell2Stored = cell2.getEnergyStored("right")
  23.   cell2Full = cell2.getMaxEnergyStored("right")
  24.   cell2Precent = math.floor(100*cell2Stored/cell2Full)
  25.   cell2Bar = math.floor(cell2Precent/5)
  26.  
  27.   --3.Cell
  28.   cell3Stored = cell3.getEnergyStored("right")
  29.   cell3Full = cell3.getMaxEnergyStored("right")
  30.   cell3Precent = math.floor(100*cell3Stored/cell3Full)
  31.   cell3Bar = math.floor(cell3Precent/5)
  32.  
  33.   --4.Cell
  34.   cell4Stored = cell4.getEnergyStored("right")
  35.   cell4Full = cell4.getMaxEnergyStored("right")
  36.   cell4Precent = math.floor(100*cell4Stored/cell4Full)
  37.   cell4Bar = math.floor(cell4Precent/5)
  38. end
  39.  
  40. function reset()
  41.         mon.clear()
  42.         mon.setTextColor(colors.white)
  43.         mon.setCursorPos(1,1)
  44. end
  45.  
  46. function draw()
  47.   --1.Cell
  48.   if cell1Precent < 30 then
  49.     mon.setTextColor(colors.red)
  50.   elseif (cell1Precent > 30) and (cell1Precent < 60) then
  51.     mon.setTextColor(colors.yellow)
  52.   else
  53.     mon.setTextColor(colors.lime)
  54.   end
  55.   mon.write("1.Stored:"..tonumber(cell1Stored).."RF")
  56.   mon.setCursorPos(1,2)
  57.   mon.write("1.Max:"..tonumber(cell1Full).."RF")
  58.   mon.setCursorPos(1,3)
  59.   mon.write("1.Precent:"..tonumber(cell1Precent).."% ")
  60.   mon.setCursorPos(16,3)
  61.   mon.setBackgroundColor(colors.blue)
  62.   for i = 1, 20 do
  63.     mon.write(" ")
  64.   end
  65.   mon.setBackgroundColor(colors.orange)
  66.   mon.setCursorPos(16,3)
  67.   for i = 1, cell1Bar do
  68.     mon.write(" ")
  69.   end
  70.  
  71.   --2.Cell
  72.   mon.setBackgroundColor(colors.black)
  73.   mon.setCursorPos(1,5)
  74.   if cell2Precent < 30 then
  75.     mon.setTextColor(colors.red)
  76.   elseif (cell2Precent > 30) and (cell2Precent < 60) then
  77.     mon.setTextColor(colors.yellow)
  78.   else
  79.     mon.setTextColor(colors.lime)
  80.   end
  81.   mon.write("2.Stored:"..tonumber(cell2Stored).."RF")
  82.   mon.setCursorPos(1,6)
  83.   mon.write("2.Max:"..tonumber(cell2Full).."RF")
  84.   mon.setCursorPos(1,7)
  85.   mon.write("2.Precent:"..tonumber(cell2Precent).."% ")
  86.   mon.setCursorPos(16,7)
  87.   mon.setBackgroundColor(colors.blue)
  88.   for i = 1, 20 do
  89.     mon.write(" ")
  90.   end
  91.   mon.setBackgroundColor(colors.orange)
  92.   mon.setCursorPos(16,7)
  93.   for i = 1, cell2Bar do
  94.     mon.write(" ")
  95.   end
  96.  
  97.   --3.Cell
  98.   mon.setBackgroundColor(colors.black)
  99.   mon.setCursorPos(1,9)
  100.   if cell3Precent < 30 then
  101.     mon.setTextColor(colors.red)
  102.   elseif (cell3Precent > 30) and (cell3Precent < 60) then
  103.     mon.setTextColor(colors.yellow)
  104.   else
  105.     mon.setTextColor(colors.lime)
  106.   end
  107.   mon.write("3.Stored:"..tonumber(cell3Stored).."RF")
  108.   mon.setCursorPos(1,10)
  109.   mon.write("3.Max:"..tonumber(cell3Full).."RF")
  110.   mon.setCursorPos(1,11)
  111.   mon.write("3.Precent:"..tonumber(cell3Precent).."%")
  112.   mon.setCursorPos(16,11)
  113.   mon.setBackgroundColor(colors.blue)
  114.   for i = 1, 20 do
  115.     mon.write(" ")
  116.   end
  117.   mon.setBackgroundColor(colors.orange)
  118.   mon.setCursorPos(16,11)
  119.   for i = 1, cell3Bar do
  120.     mon.write(" ")
  121.   end
  122.  
  123.   --4.Cell
  124.   mon.setBackgroundColor(colors.black)
  125.   mon.setCursorPos(1,13)
  126.   if cell4Precent < 30 then
  127.     mon.setTextColor(colors.red)
  128.   elseif (cell4Precent > 30) and (cell4Precent < 60) then
  129.     mon.setTextColor(colors.yellow)
  130.   else
  131.     mon.setTextColor(colors.lime)
  132.   end
  133.   mon.write("4.Stored:"..tonumber(cell4Stored).."RF")
  134.   mon.setCursorPos(1,14)
  135.   mon.write("4.Max:"..tonumber(cell4Full).."RF")
  136.   mon.setCursorPos(1,15)
  137.   mon.write("4.Precent:"..tonumber(cell4Precent).."%")
  138.   mon.setCursorPos(16,15)
  139.   mon.setBackgroundColor(colors.blue)
  140.   for i = 1, 20 do
  141.     mon.write(" ")
  142.   end
  143. mon.setBackgroundColor(colors.orange)
  144. mon.setCursorPos(16,15)
  145.   for i = 1, cell4Bar do
  146.     mon.write(" ")
  147.   end
  148.   mon.setBackgroundColor(colors.black)
  149.   sleep(1)
  150. end
  151. calculate()
  152. reset()
  153. draw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement