tommy2805

programma ascensore piano 1

Jun 1st, 2024 (edited)
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. -- Inizializza Rednet
  2. rednet.open("bottom")
  3.  
  4. --ID dei computer receiver
  5. local targetIDs = {21, 23, 25}
  6.  
  7.  
  8. -- invio a tutti i target ID
  9. local function sendToAll(message)
  10.     for _, id in ipairs(targetIDs) do
  11.         rednet.send(id, message)
  12.     end
  13. end
  14.  
  15. -- controllo il segnale redstone e invio messaggi
  16. function checkRedstoneSignals()
  17.     local leftSignal = redstone.getInput("left")
  18.     local rightSignal = redstone.getInput("right")
  19.  
  20.     while true do
  21.         local newleftSignal = redstone.getInput("left")
  22.         local newrightSignal = redstone.getInput("right")
  23.  
  24.         -- Sopra è cambiato da acceso a spento
  25.         if leftSignal and not newleftSignal then
  26.             redstone.setOutput("top", false)
  27.             sendToAll("lasciando piano 1")
  28.             print("lasciando piano 1")
  29.         end
  30.  
  31.         -- sopra è cambiato da spento ad acceso
  32.         if not leftSignal and newleftSignal then
  33.             redstone.setOutput("top", true)
  34.             sendToAll("stop")
  35.             print("stop")
  36.         end
  37.  
  38.         -- sinistra è cambiato da acceso a spento
  39.         if rightSignal and not newrightSignal then
  40.             sendToAll("lasciando piano 2")
  41.             print("lasciando piano 2")
  42.         end
  43.  
  44.         -- sinistra è cambiato da spento ad acceso
  45.         if not rightSignal and newrightSignal then
  46.             sendToAll("stop")
  47.             print("stop")
  48.         end
  49.  
  50.         -- Aggiorna gli stati dei segnali
  51.         leftSignal = newleftSignal
  52.         rightSignal = newrightSignal
  53.  
  54.         -- dormi dormi fiorellino
  55.         sleep(0.3)
  56.     end
  57. end
  58.  
  59. -- inizio
  60. checkRedstoneSignals()
Advertisement
Add Comment
Please, Sign In to add comment