geremy44

Monitor V2

Feb 10th, 2022 (edited)
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.66 KB | None | 0 0
  1. --ID : 2
  2. local mon = peripheral.wrap("back")
  3. local i = 0
  4. rednet.open("right")
  5.  
  6. function DrawButton()
  7.     mon.setTextColor(colors.black)
  8.     mon.setCursorPos(2,4)
  9.     mon.setBackgroundColor(colors.green)
  10.     mon.write("        ")
  11.     mon.setCursorPos(2,5)
  12.     mon.setBackgroundColor(colors.green)
  13.     mon.write("   On   ")
  14.     mon.setCursorPos(2,6)
  15.     mon.setBackgroundColor(colors.green)
  16.     mon.write("        ")
  17.     mon.setCursorPos(12,4)
  18.     mon.setBackgroundColor(colors.red)
  19.     mon.write("        ")
  20.     mon.setCursorPos(12,5)
  21.     mon.setBackgroundColor(colors.red)
  22.     mon.write("  STOP  ")
  23.     mon.setCursorPos(12,6)
  24.     mon.setBackgroundColor(colors.red)
  25.     mon.write("        ")
  26.     mon.setBackgroundColor(colors.black)
  27. end
  28.  
  29. mon.setTextScale(1)
  30. mon.clear()
  31. DrawButton()
  32.  
  33. while true do
  34.  
  35.     --Demande l'etat du reacteur--
  36.     rednet.broadcast("Etat?")
  37.    
  38.     --Reçois l'etat du reacteur--
  39.     local event, side, xPos, yPos = os.pullEvent()  --on range dans les variables le contenu de l'event
  40.  
  41.     if (event == "modem_message") then --si l'evenement est un message rednet, que l'emeteur est le PC 1 et que le protocole du message est l'etat du reacteur
  42.  
  43.         local ID, Message, Protocole = rednet.receive()
  44.  
  45.         if (ID == 1) and (Protocole == "Etat") then                                              --si le contenu du message est "On"
  46.             if (Message == "On") then
  47.              --affichage
  48.                 mon.setCursorPos(1,1)
  49.                 mon.write("            ")
  50.                 mon.setCursorPos(1,1)
  51.                 mon.setTextColor(colors.green)
  52.                 mon.write("Reacteur On")
  53.  
  54.             elseif (Message == "Off") then                                         --si le contenu du message est "Off"
  55.  
  56.                 --affichage
  57.                  mon.setCursorPos(1,1)
  58.                  mon.write("            ")
  59.                 mon.setCursorPos(1,1)
  60.                 mon.setTextColor(colors.red)
  61.                 mon.write("Reacteur Off")
  62.             end
  63.         end
  64.  
  65.     end
  66.     sleep(0.1)
  67.  
  68.     --Demande la production du reacteur--
  69.     rednet.broadcast("Prod?")
  70.  
  71.     --Reçois la prod--
  72.     local event, side, xPos, yPos = os.pullEvent()  --on range dans les variables le contenu de l'event
  73.  
  74.     if (event == "modem_message") then
  75.  
  76.         local ID, Message, Protocole = rednet.receive()
  77.  
  78.         if (ID == 1) and (Protocole == "Prod") then
  79.             mon.setCursorPos(1,2)
  80.             mon.write("                              ")
  81.             mon.setCursorPos(1,2)
  82.             mon.setTextColor(colors.orange)
  83.             mon.write("Production :"..Message.." RF/t")
  84.         end
  85.  
  86.     end
  87.     sleep(0.1)
  88.  
  89.     --Demande le stockage du reacteur--
  90.     rednet.broadcast("Stor?")
  91.  
  92.     --Reçois le Stor--
  93.     local event, side, xPos, yPos = os.pullEvent()  --on range dans les variables le contenu de l'event
  94.  
  95.     if (event == "modem_message") then
  96.        
  97.         local ID, Message, Protocole = rednet.receive()
  98.  
  99.         if (ID == 1) and (Protocole == "Stor") then
  100.             mon.setCursorPos(1,3)
  101.             mon.write("                          ")
  102.             mon.setCursorPos(1,3)
  103.             mon.setTextColor(colors.magenta)
  104.             mon.write("Stoquage :"..Message.." RF")
  105.         end
  106.  
  107.     end
  108.     sleep(0.1)
  109.  
  110.     local event, side, xPos, yPos = os.pullEvent()
  111.  
  112.     if (event == "monitor_touch") then
  113.  
  114.         if (((xPos < 10) and (xPos > 2)) and ((yPos < 6) and (yPos > 4))) then
  115.             rednet.send(1,"On","Etat")
  116.         elseif (((xPos < 20) and (xPos > 12)) and ((yPos < 6) and (yPos > 4))) then
  117.             rednet.send(1,"Off","Etat")
  118.         end
  119.  
  120.     end
  121.  
  122. end
  123.  
Add Comment
Please, Sign In to add comment