Advertisement
On_The_Edge

Vertikale Füllstandsanzeige real Data V3

Feb 23rd, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.00 KB | None | 0 0
  1. -- Komponenten --
  2. event.ignoreAll()
  3. gpu1 = computer.getGPUs(1)[1]
  4. Screen = component.proxy("FEC3E5EA47C6B134A9613FB0CC51CCD3")
  5. Tank1 = component.proxy("E19432AE46CCC08F1A5D09969E33CF85")
  6. Tank2 = component.proxy("98A62C4B4C2233627321D1B30816F8E5")
  7.  
  8. gpu1:bindScreen(Screen)
  9. gpu1:setsize(100,20)
  10. gpu1:setForeground(1,1,1,1)
  11. gpu1:setBackground(0,0,0,0)
  12.  
  13. -- OPTION --
  14. Tank1:flush()
  15. -- Tank2:flush()
  16.  
  17. -- DATEN --
  18. z = 0 -- Zeilenreset
  19. o = 5 -- oberes ende
  20. u = o+13 -- unteres ende
  21. T = 3 -- Anzahl der Tanks
  22. h = {}
  23. p = {}
  24.  
  25. function getdata()
  26.  
  27. VS = {}
  28. VS = {Tank1.fluidcontent, Tank2.fluidcontent, Tank2.fluidcontent}
  29.  
  30. xv = 1 -- Datensatz Start 1
  31. T = 3 -- Anzahl der Tanks
  32.  
  33. for i = 1,T,1 do -- Daten schreiben
  34. VS[xv] = math.floor(VS[xv]) -- runden --
  35. if VS[xv] > 2400 then VS[xv] = 2400
  36. end
  37. xv = xv +1
  38. end
  39.  
  40. hx = 1 -- Start h = 1
  41. for i = 1,T,1 do -- Prozente für Balken ausrechnen
  42. h[hx] = VS[hx]
  43. p[hx] = math.floor((100/2400)*h[hx]/10)
  44. -- print ((h[hx]), (p[hx]))
  45. hx = hx + 1
  46. end
  47. end
  48.  
  49. -- AUSGABE --
  50. function stream()
  51. gpu1:fill(0,0,100,20," ")
  52.  
  53. x = 5 -- x Spalte für Anzeigen vom linken Rand
  54.  
  55. -- Display Titel --
  56. gpu1:setText(5,1,"S U P E R C O M P U T E R // F U E L  T A N K S")
  57. gpu1:SetBackground(60,60,60,0.3)
  58. gpu1:fill(5,2,47,1," ")
  59.  
  60. function Zahlenformat() -- Anzeige der Zahl je nach Länge der Zahl
  61. if Z < 10 then Z = "   "..h[hx]
  62. return Z
  63. end
  64.  
  65. if Z < 100 then Z = "  "..h[hx]
  66. return Z
  67. end
  68.  
  69. if Z < 1000 then Z = " "..h[hx]
  70. return Z
  71. end
  72. end
  73.  
  74. -- Farbe der Balken festlegen --
  75. function Balkenfarbe()
  76. if Z < 400 then gpu1:setBackground(255,0,0,1)
  77. end
  78. if Z >= 400 and Z < 2000 then gpu1:setBackground(255,165,0,1)
  79. end
  80. if Z >= 2000 then gpu1:setBackground(0,255,0,1)
  81. end
  82. end
  83.  
  84.  
  85. -- Tank 1 --
  86. hx = 1  -- Datensatz 1 starten
  87. Z = h[hx]
  88. Balkenfarbe()
  89. Zahlenformat()
  90. if VS[hx] < 240 then p[hx] = 1
  91. end
  92. gpu1:fill(x+1,u-p[hx],2,p[hx]," ") -- Füllstand Balken zeichnen
  93. gpu1:setBackground(0,0,0,0)
  94. gpu1:setText(x,u,"----")
  95. gpu1:fill(x,o+3,1,10,"|")
  96. gpu1:fill(x+3,o+3,1,10,"|")
  97. gpu1:setText(x,o+2,"----")
  98. gpu1:setText(x,o+1,Z)
  99. gpu1:setText(x,o,"----")
  100. gpu1:setText(x,o-1," T1")
  101.  
  102. -- Tank 2 --
  103. x = x + 7 -- Abstand der Anzeigen zueinander
  104. hx = hx +1
  105. Z = h[hx]
  106. Balkenfarbe()
  107. Zahlenformat()
  108. if VS[hx] < 240 then p[hx] = 1
  109. end
  110. gpu1:fill(x+1,u-p[hx],2,p[hx]," ")
  111. gpu1:setBackground(0,0,0,0)
  112. gpu1:setText(x,u,"----")
  113. gpu1:fill(x,o+3,1,10,"|")
  114. gpu1:fill(x+3,o+3,1,10,"|")
  115. gpu1:setText(x,o+2,"----")
  116. gpu1:setText(x,o+1,Z)
  117. gpu1:setText(x,o,"----")
  118. gpu1:setText(x,o-1," T2")
  119.  
  120. -- Tank 3 --
  121. x = x + 7 -- Abstand der Anzeigen zueinander
  122. hx = hx +1
  123. Z = h[hx]
  124. Balkenfarbe()
  125. Zahlenformat()
  126. if VS[hx] < 240 then p[hx] = 1
  127. end
  128. gpu1:fill(x+1,u-p[hx],2,p[hx]," ")
  129. gpu1:setBackground(0,0,0,0)
  130. gpu1:setText(x,u,"----")
  131. gpu1:fill(x,o+3,1,10,"|")
  132. gpu1:fill(x+3,o+3,1,10,"|")
  133. gpu1:setText(x,o+2,"----")
  134. gpu1:setText(x,o+1,Z)
  135. gpu1:setText(x,o,"----")
  136. gpu1:setText(x,o-1," T2")
  137.  
  138. gpu1:flush()
  139. end
  140.  
  141. -- RUN --
  142. while true do
  143. event.pull(2)
  144. getdata()
  145. stream()
  146. hx = 1
  147. Z = ""
  148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement