Minenat69

Engine controllers program

Aug 1st, 2023 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. function wait ( time )
  2. local timer = os.startTimer(time)
  3. while true do
  4. local event = {os.pullEvent()}
  5. if (event[1] == "timer" and event[2] == timer) then
  6. break
  7. elseif event[1] == "monitor_touch" then
  8. print("Other event catched")
  9. end
  10. end
  11. end
  12.  
  13. function turnOffEngine()
  14. redstone.setOutput("right", true)
  15. wait(2)
  16. redstone.setOutput("right", false)
  17. end
  18.  
  19. function turnOnEngine()
  20. redstone.setOutput("left", true)
  21. wait(8)
  22. redstone.setOutput("left", false)
  23. end
  24.  
  25. function getEvent()
  26. local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  27.  
  28. --print("I just received a message on channel: "..senderChannel)
  29. --print("The message was: "..message)
  30.  
  31. -- Tells to turn on engine
  32. if message == "turn_on" then
  33. turnOnEngine()
  34. -- Turn off the engine
  35. elseif message == "turn_off" then
  36. turnOffEngine()
  37. end
  38.  
  39. getEvent()
  40. end
  41.  
  42. engine_number = tonumber(arg[1])
  43. modem = peripheral.wrap("top")
  44. modem.open(engine_number)
  45. getEvent()
Advertisement
Add Comment
Please, Sign In to add comment