Advertisement
CdoubleOK

Ref switch control 1

May 1st, 2023 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.61 KB | None | 0 0
  1. local modem = peripheral.find("modem")
  2. local outputMap = {
  3.   [2] = "left",
  4.   [3] = "right",
  5.   [4] = "front",
  6.   [5] = "back"
  7. }
  8.  
  9. term.clear()
  10. term.setCursorPos(1,1)
  11. print("Running")
  12.  
  13. while rs.getInput("front") == false do
  14.   modem.open(26)
  15.   local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  16.   modem.close(26)
  17.  
  18.   if outputMap[replyChannel] and message == "On" then
  19.     rs.setOutput(outputMap[replyChannel], true)
  20.   end
  21.    
  22.   if outputMap[replyChannel] and message == "Off" then
  23.     rs.setOutput(outputMap[replyChannel], false)
  24.   end
  25.    
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement