Advertisement
On_The_Edge

Vertikale Füllstandsanzeige Table mit realen Daten V2

Feb 23rd, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 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 = 2 -- Anzahl der Tanks
  22. h = {}
  23. p = {}
  24.  
  25. function getdata()
  26. V1 = Tank1.fluidcontent
  27. V1 = math.floor(V1) -- runden --
  28. if V1 > 2400 then V1 = 2400
  29. end
  30.  
  31. V2 = Tank2.fluidcontent
  32. V2 = math.floor(V2) -- runden --
  33. if V2 > 2400 then V2 = 2400
  34. end
  35. -- print (V1, V2)
  36.  
  37. hx = 1 -- Start h = 1
  38. VS = {V1, V2}
  39.  
  40. for i = 1,T,1 do
  41. h[hx] = VS[hx]
  42. p[hx] = math.floor((100/2400)*h[hx]/10)
  43. -- print ((h[hx]), (p[hx]))
  44. hx = hx + 1
  45. end
  46. end
  47.  
  48. -- AUSGABE --
  49. function stream()
  50. gpu1:fill(0,0,100,20," ")
  51.  
  52. x = 5 -- x Spalte für Anzeigen vom linken Rand
  53.  
  54. function Zahlenformat() -- Anzeige der Zahl je nach Länge der Zahl
  55. if Z < 10 then Z = "   "..h[hx]
  56. return Z
  57. end
  58.  
  59. if Z < 100 then Z = "  "..h[hx]
  60. return Z
  61. end
  62.  
  63. if Z < 1000 then Z = " "..h[hx]
  64. return Z
  65. end
  66. end
  67.  
  68. -- Farbe der Balken festlegen --
  69. function Balkenfarbe()
  70. if Z < 400 then gpu1:setBackground(255,0,0,1)
  71. end
  72. if Z >= 400 and Z < 2000 then gpu1:setBackground(255,165,0,1)
  73. end
  74. if Z >= 2000 then gpu1:setBackground(0,255,0,1)
  75. end
  76. end
  77.  
  78.  
  79. -- Tank 1 --
  80. hx = 1  -- Datensatz 1 starten
  81. Z = h[hx]
  82. Balkenfarbe()
  83. Zahlenformat()
  84. if VS[hx] < 240 then p[hx] = 1
  85. end
  86. -- print(V1, (u-p[hx]), p[hx])
  87. gpu1:fill(x+1,u-p[hx],2,p[hx]," ") -- Füllstand Balken zeichnen
  88. gpu1:setBackground(0,0,0,0)
  89. gpu1:setText(x,u,"----")
  90. gpu1:fill(x,o+3,1,10,"|")
  91. gpu1:fill(x+3,o+3,1,10,"|")
  92. gpu1:setText(x,o+2,"----")
  93. gpu1:setText(x,o+1,Z)
  94. gpu1:setText(x,o,"----")
  95. gpu1:setText(x,o-1," T1")
  96.  
  97. -- Tank 2 --
  98. x = x + 7 -- Abstand der Anzeigen zueinander
  99. hx = hx +1
  100. Z = h[hx]
  101. Balkenfarbe()
  102. Zahlenformat()
  103. if VS[hx] < 240 then p[hx] = 1
  104. end
  105. gpu1:fill(x+1,u-p[hx],2,p[hx]," ")
  106. gpu1:setBackground(0,0,0,0)
  107. gpu1:setText(x,u,"----")
  108. gpu1:fill(x,o+3,1,10,"|")
  109. gpu1:fill(x+3,o+3,1,10,"|")
  110. gpu1:setText(x,o+2,"----")
  111. gpu1:setText(x,o+1,Z)
  112. gpu1:setText(x,o,"----")
  113. gpu1:setText(x,o-1," T2")
  114.  
  115.  
  116. gpu1:flush()
  117. end
  118.  
  119. -- RUN --
  120. while true do
  121. event.pull(2)
  122. getdata()
  123. stream()
  124. hx = 1
  125. Z = ""
  126. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement