Advertisement
lego11

Quadro elettrico kiwi test

Jan 13th, 2019
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. uscite = 0;
  2.  
  3. function clear()
  4. term.clear()
  5. term.setCursorPos(1, 1)
  6. term.setBackgroundColour(colours.black)
  7. term.setTextColor(colors.white)
  8. end
  9.  
  10. function colore()
  11. term.setTextColour(sfumatura)
  12. end
  13.  
  14. function fineColore()
  15. term.setTextColour(colours.white)
  16. end
  17.  
  18. function sfondo(sfumaturaSfondo)
  19. term.setBackgroundColour(sfumaturaSfondo)
  20. end
  21.  
  22. function fineSfondo()
  23. term.setBackgroundColour(colours.black)
  24. end
  25.  
  26. function leggiStatoUscite()
  27. if fs.exists("uscite") == true then
  28. handle = fs.open("uscite", "r")
  29. uscite = tonumber(handle.readAll())
  30. handle.close()
  31. else
  32. handle = fs.open("uscite", "w")
  33. handle.write(tostring(uscite))
  34. handle.close()
  35. end
  36. end
  37.  
  38. function salvaStatoUscite()
  39. handle = fs.open("uscite", "w")
  40. handle.write(tostring(uscite))
  41. handle.close()
  42. end
  43.  
  44. function attivaUscite()
  45. rs.setBundledOutput("back", uscite)
  46. end
  47.  
  48. function controllaSeAcceso(binario)
  49. if colors.test(rs.getBundledInput("back"), binario) == true then
  50. return true
  51. else
  52. return false
  53. end
  54. end
  55.  
  56. function disegnaOnOff(coloreCavoOnOff)
  57. if colors.test(uscite, coloreCavoOnOff) == true then
  58. sfondo(colors.lime)
  59. term.write("ON")
  60. fineSfondo()
  61. else
  62. sfondo(colors.red)
  63. term.write("OFF")
  64. fineSfondo()
  65. end
  66. end
  67.  
  68.  
  69. function disegnaStrutturaQuadro()
  70. clear()
  71. print("Quadro elettrico (C) lego11\n")
  72.  
  73. print("Trasformatore 1 raffineria")
  74. print("Trasformatore 2 raffineria")
  75. print("Trasformatore 3 raffineria")
  76. print("Linea 32kW massfab")
  77. print("Linea 128kW massfab")
  78. print("Caldaia liquami")
  79.  
  80. term.setCursorPos(44,3)
  81. disegnaOnOff(1)
  82. term.setCursorPos(44,4)
  83. disegnaOnOff(2)
  84. term.setCursorPos(44,5)
  85. disegnaOnOff(4)
  86. term.setCursorPos(44,6)
  87. disegnaOnOff(8)
  88. term.setCursorPos(44,7)
  89. disegnaOnOff(16)
  90. term.setCursorPos(44,8)
  91. disegnaOnOff(32)
  92. end
  93.  
  94. leggiStatoUscite()
  95. attivaUscite()
  96.  
  97. while true do
  98. attivaUscite()
  99. disegnaStrutturaQuadro()
  100. evento, pulsante, x, y = os.pullEvent( "mouse_click" )
  101. if y == 3 then
  102. if controllaSeAcceso(1) == true then
  103. uscite = uscite - 1
  104. else
  105. uscite = uscite + 1
  106. end
  107. elseif y == 4 then
  108. if controllaSeAcceso(2) == true then
  109. uscite = uscite - 2
  110. else
  111. uscite = uscite + 2
  112. end
  113. elseif y == 5 then
  114. if controllaSeAcceso(4) == true then
  115. uscite = uscite - 4
  116. else
  117. uscite = uscite + 4
  118. end
  119. elseif y == 6 then
  120. if controllaSeAcceso(8) == true then
  121. uscite = uscite - 8
  122. else
  123. uscite = uscite + 8
  124. end
  125. elseif y == 7 then
  126. if controllaSeAcceso(16) == true then
  127. uscite = uscite - 16
  128. else
  129. uscite = uscite + 16
  130. end
  131. elseif y == 8 then
  132. if controllaSeAcceso(32) == true then
  133. uscite = uscite - 32
  134. else
  135. uscite = uscite + 32
  136. end
  137. else
  138. uscite = uscite
  139. end
  140. salvaStatoUscite()
  141. sleep(1)
  142. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement