lego11

Balakovo energia 2

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