Advertisement
colhaydutu

atm test1

Jan 22nd, 2024 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. local function findMonitors()
  2. local monitors = {}
  3. for _, name in pairs(peripheral.getNames()) do
  4. if string.match(name, "^monitor_") then
  5. local monitor = peripheral.wrap(name)
  6. table.insert(monitors, monitor)
  7. end
  8. end
  9. return monitors
  10. end
  11.  
  12. local function drawBar(monitor, x, y, width, fillPercentage)
  13. local w, h = monitor.getSize()
  14. term.redirect(monitor)
  15. paintutils.drawLine(3, 3, 4, 3, colors.lime)
  16. paintutils.drawLine(13, 3, w - 2, 3, colors.lime)
  17. paintutils.drawLine(3, 3, 3, h - 1, colors.lime)
  18. paintutils.drawLine(w - 2, 3, w - 2, h - 1, colors.lime)
  19. paintutils.drawLine(w - 2, h - 1, 3, h - 1, colors.lime)
  20.  
  21. monitor.setBackgroundColor(colors.gray)
  22. monitor.setTextColor(colors.black)
  23. monitor.setCursorPos(6, 3)
  24. monitor.write("[INFO]")
  25.  
  26. local fillWidth = math.floor(width * fillPercentage)
  27.  
  28. monitor.setBackgroundColor(colors.gray)
  29. monitor.setTextColor(colors.black)
  30.  
  31. monitor.setCursorPos(x, y)
  32. monitor.write("[ ")
  33.  
  34. for i = 1, width do
  35. if i <= fillWidth then
  36. monitor.setBackgroundColor(colors.green)
  37. monitor.write(" ")
  38. else
  39. monitor.setBackgroundColor(colors.red)
  40. monitor.write(" ")
  41. end
  42. end
  43.  
  44. monitor.setBackgroundColor(colors.gray)
  45. monitor.write(" ] " .. math.floor(fillPercentage * 100) .. "%")
  46. end
  47.  
  48. local jouleToFeRatio = 276 / 690 -- 1 J = (276 / 690) Fe
  49.  
  50. local monitors = findMonitors()
  51.  
  52. if #monitors == 0 then
  53. print("No monitors found. Please connect a monitor.")
  54. return
  55. end
  56.  
  57. local monitor = monitors[1]
  58. local modem = peripheral.wrap("back")
  59. modem.open(11)
  60.  
  61. local battery
  62. for _, name in pairs(peripheral.getNames()) do
  63. if string.match(name, "^inductionPort_0") then
  64. battery = peripheral.wrap(name)
  65. break
  66. end
  67. end
  68.  
  69. if not battery then
  70. print("IC2 battery not found. Please use modem and right-click on it to connect.")
  71. return
  72. end
  73.  
  74. while true do
  75. local totalEnergyJoule = battery.getEnergy()
  76. local capPercentageJoule = battery.getEnergyFilledPercentage() or 0
  77.  
  78. local totalEnergyFe = totalEnergyJoule * jouleToFeRatio
  79. local capPercentageFe = capPercentageJoule -- Remove unnecessary multiplication
  80.  
  81. monitor.clear()
  82. drawBar(monitor, 5, 7, 20, capPercentageFe)
  83.  
  84. monitor.setCursorPos(5, 5)
  85. monitor.setBackgroundColor(colors.gray)
  86. monitor.setTextColor(colors.black)
  87. monitor.write("Energy: " .. string.format("%.2f", totalEnergyFe / 1000) .. " kFe") -- Display in kFe
  88.  
  89. os.sleep(1)
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement