Advertisement
themadgod

monitor

Oct 2nd, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. mon = peripheral.wrap("bottom")
  2. mon.clear()
  3.  
  4. function paintText(energy)
  5. if energy > 75 then
  6. mon.setTextColor(colors.green)
  7. elseif energy > 25 then
  8. mon.setTextColor(colors.yellow)
  9. else
  10. mon.setTextColor(colors.red)
  11. end
  12. end
  13.  
  14. function resetColor()
  15. mon.setTextColor(colors.white)
  16. end
  17.  
  18.  
  19. if mon == nil then
  20. print("Monitor not found.")
  21. end
  22.  
  23.  
  24. function draw(info)
  25. print("Updating monitor...")
  26. local mon = peripheral.wrap("bottom")
  27. mon.clear()
  28. local w, h = mon.getSize()
  29. local x = 1
  30. local y = 1
  31. mon.setTextScale(1.5)
  32. mon.setCursorPos(x, y)
  33. mon.write("Energy: ")
  34. local ePercent = math.floor(info.energy*1000)/10
  35. mon.write( ePercent.."%")
  36.  
  37. paintText(ePercent)
  38. mon.setCursorPos(x, y+1)
  39. local ePer = (info.energy) * 20
  40. mon.write( string.rep("#", math.floor(ePer) ) )
  41. mon.write( string.rep("-", 20 - math.floor(ePer)))
  42. resetColor()
  43.  
  44. mon.setCursorPos(x, y+2)
  45. mon.write("Fuel: ")
  46.  
  47. local fPercent = math.floor(info.fuel*1000)/10
  48. mon.write(fPercent.."%")
  49.  
  50. paintText(fPercent)
  51. mon.setCursorPos(x, y+3)
  52. local fPer = (info.fuel) * 20
  53. mon.write( string.rep("#", math.floor(fPer)))
  54. mon.write( string.rep("-", 20 - math.floor(fPer)))
  55. resetColor()
  56.  
  57. mon.setCursorPos(x, y+4)
  58. mon.write("RF/t: ")
  59. mon.write(info.rfptick)
  60.  
  61. mon.setCursorPos(x, y+6)
  62. mon.write("Fuel/t: ")
  63. local fuelPerTick = math.floor(info.rfptick*10000)/10000
  64. mon.write(fuelPerTick)
  65.  
  66. mon.setCursorPos(x,y+7)
  67. mon.write("Status: ")
  68. if(info.active) then
  69. mon.setTextColor(colors.green)
  70. mon.write("ONLINE")
  71. else
  72. mon.setTextColor(colors.red)
  73. mon.write("OFFLINE")
  74. end
  75. end
  76.  
  77. function calcProgress(val, max)
  78. local per = val / max
  79. local progress = per * 14
  80. return progress
  81. end
  82.  
  83.  
  84. function getInfo()
  85. rednet.open("left")
  86. print("Waiting for Signal...")
  87. local id, msg, protocol = rednet.receive()
  88.  
  89. if id == 4 then
  90. stats.fuel = msg
  91. elseif id == 16 then
  92. stats.active = msg.active
  93. stats.rfptick = msg.rfptick
  94. stats.rpm = msg.rpm
  95. elseif id == 17 then
  96. stats.energy = msg
  97. end
  98.  
  99. if msg then
  100. print("Signal Found!")
  101. return msg
  102. else
  103. return false
  104. end
  105. end
  106.  
  107. stats = {fuel = 0, active = false, rfptick = 0, rpm = 0, energy = 0}
  108.  
  109. while true do
  110. getInfo()
  111. draw(stats)
  112. resetColor()
  113. os.sleep(1)
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement