RavenSH4

ExtremeReactorControl

May 11th, 2022
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. --Global variables
  2. IsOnFlag = true
  3. mouseWidth = 0
  4. mouseHeight = 0
  5. ColorMix = 0
  6. ------------------
  7. --initialize
  8. monitor = peripheral.wrap("top")
  9. monitor.clear()
  10. monitor.setCursorPos(1,1)
  11. reactor = peripheral.wrap("back")
  12.  
  13. --Write On/Off button
  14. function WriteButtons(IsOn)
  15. monitor.setTextColor(colors.white)
  16. if IsOn == true then
  17. monitor.setBackgroundColour((colours.lime))
  18. monitor.setCursorPos(24,2)
  19. monitor.write(" ")
  20. monitor.setCursorPos(24,3)
  21. monitor.write(" ON ")
  22. monitor.setCursorPos(24,4)
  23. monitor.write(" ")
  24. else
  25. monitor.setBackgroundColour((colours.red))
  26. monitor.setCursorPos(24,2)
  27. monitor.write(" ")
  28. monitor.setCursorPos(24,3)
  29. monitor.write(" OFF ")
  30. monitor.setCursorPos(24,4)
  31. monitor.write(" ")
  32. end
  33. monitor.setBackgroundColour((colours.black))
  34. end
  35.  
  36. --Check mouse to button click
  37. function checkClickPosition()
  38. if mouseWidth >= 24 and mouseWidth <= 28 and mouseHeight >= 2 and mouseHeight <= 4 then
  39. if IsOnFlag == true then
  40. IsOnFlag = false
  41. else
  42. IsOnFlag = true
  43. end
  44.  
  45. WriteButtons(IsOnFlag)
  46. UpdateSensors()
  47. end
  48. end
  49.  
  50. --
  51. function DrawTextLine(State, Color, Line, TextH, TextOk, TextFail)
  52. monitor.setCursorPos(1,Line)
  53. monitor.setTextColor(colors.white)
  54. monitor.write(TextH)
  55. monitor.setCursorPos(14,Line)
  56. monitor.setTextColor(Color)
  57. if State then
  58. monitor.write(TextOk)
  59. else
  60. monitor.write(TextFail)
  61. end
  62. end
  63.  
  64. --
  65. function DrawValueLine(value, Color, Line, TextH)
  66. monitor.setCursorPos(1,Line)
  67. monitor.setTextColor(colors.white)
  68. monitor.write(TextH)
  69. monitor.setCursorPos(14,Line)
  70. monitor.setTextColor(Color)
  71. val = math.floor(value)
  72. monitor.write(val)
  73. end
  74.  
  75. --draw data from redstone channels (sensors)
  76. function UpdateSensors()
  77. monitor.setBackgroundColor(colours.black)
  78.  
  79. S_Status = reactor.getActive()
  80.  
  81. EnergyLevel = reactor.getEnergyStored()
  82.  
  83. PowerPercent = (EnergyLevel / 10000000) * 100
  84. PowerPercent = math.floor(PowerPercent)
  85.  
  86. RodsLevel = PowerPercent
  87.  
  88. ProduceLevel = reactor.getEnergyProducedLastTick()
  89. ProducePercent = math.floor((ProduceLevel / 3960) * 100)
  90.  
  91. DrawTextLine(S_Status , colors.green , 1, "STATUS:" , " ON " , " OFF ")
  92. DrawValueLine(PowerPercent, colors.red, 2, "ENERGY:")
  93. DrawValueLine(ProducePercent, colors.blue, 3, "POWER:")
  94. DrawValueLine(100-RodsLevel, colors.yellow, 4, "RODS: ")
  95.  
  96. reactor.setAllControlRodLevels(RodsLevel)
  97.  
  98. if IsOnFlag then
  99. reactor.setActive(true)
  100. else
  101. reactor.setActive(false)
  102. end
  103.  
  104. WriteButtons(IsOnFlag)
  105. end
  106.  
  107. w,h=monitor.getSize()
  108. print(w)
  109. print(h)
  110.  
  111. checkClickPosition()
  112. WriteButtons(false)
  113. UpdateSensors()
  114.  
  115. repeat
  116. local myTimer = os.startTimer(1)
  117.  
  118. event,p1,p2,p3 = os.pullEvent()
  119. if event=="monitor_touch" then
  120. mouseWidth = p2 -- sets mouseWidth
  121. mouseHeight = p3 -- and mouseHeight
  122. checkClickPosition() -- this runs our function
  123. end
  124.  
  125. if event=="timer" then
  126. UpdateSensors()
  127. end
  128. until event=="char" and p1==("q")
Advertisement
Add Comment
Please, Sign In to add comment