FoxWorn3365

Gestione ascensore

Apr 6th, 2022 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. -- FoxInvest Holding
  2. ----------------------
  3. -- Titanus Elios
  4. -- Gestione dell'ASCENSORE 01
  5. -----------------------
  6.  
  7. rednet.open("back")
  8.  
  9. maxw, maxh = term.getSize()
  10. local function drawPixelInternal(xPos, yPos)
  11. term.setCursorPos(xPos, yPos)
  12. term.write(" ")
  13. end
  14.  
  15. local tColourLookup = {}
  16. for n = 1, 16 do
  17. tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  18. end
  19.  
  20. function drawFilledBox(startX, startY, endX, endY, nColour)
  21. if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  22. "number" or type(endY) ~= "number" or
  23. (nColour ~= nil and type(nColour) ~= "number") then
  24. error("Expected startX, startY, endX, endY, colour", 2)
  25. end
  26.  
  27. startX = math.floor(startX)
  28. startY = math.floor(startY)
  29. endX = math.floor(endX)
  30. endY = math.floor(endY)
  31.  
  32. if nColour then term.setBackgroundColor(nColour) end
  33. if startX == endX and startY == endY then
  34. drawPixelInternal(startX, startY)
  35. return
  36. end
  37.  
  38. local minX = math.min(startX, endX)
  39. if minX == startX then
  40. minY = startY
  41. maxX = endX
  42. maxY = endY
  43. else
  44. minY = endY
  45. maxX = startX
  46. maxY = startY
  47. end
  48.  
  49. for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  50. end
  51.  
  52. function clear()
  53. sfondo(colors.black)
  54. term.clear()
  55. term.setCursorPos(1, 1)
  56. end
  57.  
  58. function clearRed()
  59. sfondo(colors.red)
  60. term.clear()
  61. term.setCursorPos(1, 1)
  62. end
  63.  
  64. function titolo(testo)
  65. drawFilledBox(1, 1, maxw, 1, colors.white)
  66. term.setCursorPos((maxw - #testo) / 2, 1)
  67. term.setTextColor(colors.black)
  68. term.write(testo)
  69. no()
  70. end
  71.  
  72. function bottone(color, text, x, y)
  73. term.setBackgroundColor(colors[color])
  74. term.setTextColor(colors.white)
  75. term.setCursorPos(x, y)
  76. print(text)
  77. end
  78.  
  79. function no()
  80. term.setBackgroundColor(colors.black)
  81. term.setTextColor(colors.white)
  82. end
  83.  
  84. function alarm(color, text)
  85. term.setBackgroundColor(colors[color])
  86. term.setTextColor(colors.white)
  87. print(" "..text.." ")
  88. no()
  89. end
  90.  
  91. function spia(x, y, color)
  92. term.setBackgroundColor(colors[color])
  93. term.setCursorPos(x, y)
  94. term.write(" ")
  95. no()
  96. end
  97.  
  98. function getStatus()
  99. rednet.send(5701, "status")
  100. local rID, message = rednet.receive(5)
  101. return message
  102. end
  103.  
  104. dev = 0
  105. isMovement = 0
  106.  
  107. while true do
  108. if dev == 0 then
  109. no()
  110. term.clear()
  111. titolo("Gestione ascensore 1 FIH")
  112. status = getStatus()
  113. print("\nAscensore NĀ° 01 - Deposito")
  114. print("Terminale Unico Gestione Ascensore")
  115. print("\nPiano: " .. status)
  116. print("\n\nBASSO:")
  117. print("Salita treni:")
  118. if status == 0 then
  119. bottom = "green"
  120. top = "red"
  121. todo = "VAI IN SU"
  122. td = "up"
  123. elseif status == 1 then
  124. bottom = "red"
  125. top = "green"
  126. todo = "VAI IN GIU'"
  127. td = "down"
  128. else
  129. bottom = "gray"
  130. top = "gray"
  131. todo = "ERROR!"
  132. end
  133. spia(15, 9, bottom)
  134. print("\n\nALTO:")
  135. print("Salita treni:")
  136. spia(15, 12, top)
  137. print("\n\nInfo generali:\nAscesore in movimento:")
  138. if isMovement == 0 then
  139. mov = "green"
  140. btCl = "blue"
  141. else
  142. mov = "orange"
  143. btCl = "gray"
  144. end
  145. spia(32, 15, mov)
  146. bottone("blue", todo, 20, 17)
  147. local event, key, x, y = os.pullEvent("mouse_click")
  148. if x > 20 and y == 17 then
  149. rednet.send(5701, td)
  150. isMovement = 1
  151. end
  152. end
  153. sleep(0.2)
  154. end
  155.  
Add Comment
Please, Sign In to add comment