Advertisement
lego11

Balakovo energia

Jan 14th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 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("Electrosila\n\n")
  72.  
  73. print("Linea 66 kV")
  74. print("Linea 6 kV")
  75. print("Applied ener.")
  76. print("Caricabatteria")
  77.  
  78. term.setCursorPos(13,3)
  79. disegnaOnOff(1)
  80. term.setCursorPos(13,4)
  81. disegnaOnOff(2)
  82. term.setCursorPos(13,5)
  83. disegnaOnOff(4)
  84. term.setCursorPos(13,6)
  85. disegnaOnOff(8)
  86. end
  87.  
  88. leggiStatoUscite()
  89. attivaUscite()
  90.  
  91. while true do
  92. attivaUscite()
  93. disegnaStrutturaQuadro()
  94. evento, pulsante, x, y = os.pullEvent( "monitor_touch" )
  95. if y == 3 then
  96. if controllaSeAcceso(1) == true then
  97. uscite = uscite - 1
  98. else
  99. uscite = uscite + 1
  100. end
  101. elseif y == 4 then
  102. if controllaSeAcceso(2) == true then
  103. uscite = uscite - 2
  104. else
  105. uscite = uscite + 2
  106. end
  107. elseif y == 5 then
  108. if controllaSeAcceso(4) == true then
  109. uscite = uscite - 4
  110. else
  111. uscite = uscite + 4
  112. end
  113. elseif y == 6 then
  114. if controllaSeAcceso(8) == true then
  115. uscite = uscite - 8
  116. else
  117. uscite = uscite + 8
  118. end
  119. elseif y == 7 then
  120. if controllaSeAcceso(16) == true then
  121. uscite = uscite - 16
  122. else
  123. uscite = uscite + 16
  124. end
  125. elseif y == 8 then
  126. if controllaSeAcceso(32) == true then
  127. uscite = uscite - 32
  128. else
  129. uscite = uscite + 32
  130. end
  131. else
  132. uscite = uscite
  133. end
  134. salvaStatoUscite()
  135. sleep(0.1)
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement