yoyoyyoghurtboyyyy

Untitled

Nov 26th, 2021 (edited)
1,245
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function putValue(line, text, color)
  2.     local align = 30 - string.len(text)
  3.     term.setCursorPos(align, line)
  4.     term.setTextColor(color)
  5.     print(text)
  6. end
  7.  
  8. function DrawBox(xMin, xMax, yMin, yMax, title)
  9.     term.setBackgroundColor(colors.gray)
  10.     for xPos = xMin, xMax, 1 do
  11.         term.setCursorPos(xPos, yMin)
  12.         term.write(" ")
  13.     end
  14.     for yPos = yMin, yMax, 1 do
  15.         term.setCursorPos(xMin, yPos)
  16.         term.write(" ")
  17.         term.setCursorPos(xMax, yPos)
  18.         term.write(" ")
  19.     end
  20.     for xPos = xMin, xMax, 1 do
  21.         term.setCursorPos(xPos, yMax)
  22.         term.write(" ")
  23.     end
  24.     term.setCursorPos(xMin + 4, yMin)
  25.     term.setBackgroundColor(colors.black)
  26.     term.write(" ")
  27.     term.write(title)
  28.     term.write(" ")
  29. end
  30.  
  31. function DrawProgress(xMin, xMax, yMin, yMax, percentage)
  32.     yTotal = yMax - yMin
  33.     for xPos = xMin, xMax, 1 do
  34.         term.setCursorPos(xPos, yMin)
  35.         for yPos = yMin, yMax, 1 do
  36.             yProgress = 1 - ((yPos - yMin) / yTotal)
  37.             if yProgress <= percentage then
  38.                 term.setPaletteColour(colors.green, 0x5cd65c)
  39.                 term.setBackgroundColor(colors.green)
  40.             else
  41.                 term.setPaletteColour(colors.red, 0xFF6666)
  42.                 term.setBackgroundColor(colors.red)
  43.             end
  44.             term.setCursorPos(xPos, yPos)
  45.             term.write(" ")
  46.         end
  47.     end
  48.     term.setBackgroundColor(colors.black)
  49. end
  50.  
  51. function putNumber(number)
  52.     local round = 0
  53.     local texts = ""
  54.  
  55.     if number >= 1000000000000000000 then
  56.         round = (number / 1000000000000000000)
  57.         texts = string.sub(round, 0, 3) .. "ERF"
  58.     else
  59.         if number >= 1000000000000000 then
  60.             round = (number / 1000000000000000)
  61.             texts = string.sub(round, 0, 3) .. "PRF"
  62.         else
  63.             if number >= 1000000000000 then
  64.                 round = (number / 1000000000000)
  65.                 texts = string.sub(round, 0, 3) .. "TRF"
  66.             else
  67.                 if number >= 1000000000 then
  68.                     round = (number / 1000000000)
  69.                     texts = string.sub(round, 0, 3) .. "GRF"
  70.                 else
  71.                     if number >= 1000000 then
  72.                         round = (number / 1000000)
  73.                         texts = string.sub(round, 0, 4) .. "MRF"
  74.                     else
  75.                         if number >= 1000 then
  76.                             round = (number / 1000)
  77.                             texts = string.sub(round, 0, 4) .. "kRF"
  78.                         else
  79.                             texts = string.sub(number, 0, 3) .. " RF"
  80.                         end
  81.                     end
  82.                 end
  83.             end
  84.         end
  85.     end
  86.  
  87.     return texts
  88. end
  89.  
  90. -- Initialize our interface!
  91. -- Find all of our peripherals
  92. monitor = peripheral.find("monitor")
  93. battery = peripheral.find("inductionMatrix")
  94.  
  95. -- Check and bind monitor
  96. if monitor == nil then
  97.     error("ER: No screen found to display!")
  98. else
  99.     monitor.clear()
  100.     term.redirect(monitor)
  101.     term.setCursorPos(1, 1)
  102.     term.setBackgroundColor(colors.black)
  103.  
  104.     DrawBox(2, 17, 2, 25, "ENERGY")
  105. end
  106.  
  107. -- Check if we have a battery
  108. if battery == nil then
  109.     error("ER: No battery connected to computer")
  110. end
  111.  
  112. --   -- Draw our static interface text
  113. --   term.setCursorPos(1, 2);
  114. --   print("Max RF:")
  115. --   term.setCursorPos(1, 3);
  116. --   print("Max Thru:")
  117. term.setCursorPos(1, 1)
  118. DrawBox(2, 17, 20, 25, "CURRENT")
  119. term.setTextColor(colors.green)
  120. term.setCursorPos(5, 22);
  121. print("In:")
  122. term.setTextColor(colors.red)
  123. term.setCursorPos(12, 22);
  124. print("Out:")
  125. --   term.setCursorPos(1, 7);
  126. --   print("Cur Bal:")
  127.  
  128. --   term.setCursorPos(1, 9);
  129. --   print("Stored:")
  130. --   term.setCursorPos(1, 10);
  131. --   print("Filled:")
  132. --   term.setCursorPos(1, 11);
  133. --   print("Critical:")
  134.  
  135. -- Entering our infinite loop of checking the battery
  136. -- This will refresh all information every 2 seconds
  137. alarmIsRinging = false
  138. alarmIsActive = false
  139. alarmCounter = 0
  140.  
  141. while true do
  142.  
  143.     -- batteryMaxCharge = battery.getMaxEnergy()
  144.     -- batteryMaxInOuts = battery.getTransferCap()
  145.     -- -- putValue(2, putNumber(batteryMaxCharge), colors.lightBlue)
  146.     -- -- putValue(3, putNumber(batteryMaxInOuts), colors.lightBlue)
  147.  
  148.     -- -- Get our input/output/balance battery values
  149.     batteryCurrentIn = battery.getLastInput()
  150.     batteryCurrentOut = battery.getLastOutput()
  151.  
  152.     term.setTextColor(colors.green)
  153.     term.setCursorPos(4, 23);
  154.     print(putNumber(batteryCurrentIn))
  155.  
  156.     term.setTextColor(colors.red)
  157.     term.setCursorPos(11, 23);
  158.     print(putNumber(batteryCurrentOut))
  159.  
  160.     -- batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut
  161.     -- batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red
  162.     -- batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or ""
  163.     -- putValue(7, batteryCurrentSign .. putNumber(batteryCurrentBalance), batteryCurrentColor)
  164.  
  165.     -- -- Get our statistical values
  166.     -- batteryCurrentCharge = battery.getEnergy()
  167.     -- putValue(9, putNumber(batteryCurrentCharge), colors.lightBlue)
  168.  
  169.     batteryCurrentColor = colors.red
  170.     batteryCurrentPercentage = battery.getEnergyFilledPercentage() * 100
  171.     batteryCurrent = battery.getEnergyFilledPercentage()
  172.  
  173.     if batteryCurrentPercentage > 30 then
  174.         batteryCurrentColor = colors.orange
  175.     end
  176.     if batteryCurrentPercentage > 60 then
  177.         batteryCurrentColor = colors.green
  178.     end
  179.     -- putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor)
  180.  
  181.     term.setCursorPos(1, 1)
  182.     DrawProgress(5, 14, 4, 16, batteryCurrent)
  183.  
  184.     term.setCursorPos(1, 1)
  185.     term.setTextColor(batteryCurrentColor)
  186.     term.setCursorPos(7, 18);
  187.     print(string.sub(batteryCurrentPercentage, 0, 5) .. "%")
  188.     term.setBackgroundColor(colors.black)
  189.  
  190.     -- Hey, ring the alarm!
  191.     if batteryCurrentPercentage > 10 then
  192.         alarmIsRinging = false
  193.         alarmIsActive = false
  194.     end
  195.  
  196.     if batteryCurrentPercentage < 10 and alarmIsActive == false then
  197.         alarmIsRinging = true
  198.         alarmIsActive = true
  199.         alarmCounter = 0
  200.         redstone.setOutput("back", true)
  201.     end
  202.  
  203.     if alarmIsRinging == true then
  204.         alarmCounter = alarmCounter + 1
  205.         if alarmCounter >= 10 then
  206.             redstone.setOutput("back", false)
  207.             alarmIsRinging = false
  208.         end
  209.     end
  210.  
  211.     -- Wait 2s until next iteration
  212.     os.sleep(1)
  213.  
  214. end
  215.  
RAW Paste Data