Advertisement
osmarks

FrameDoorControl

Jun 23rd, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.84 KB | None | 0 0
  1. local OPEN = colors.combine(colors.magenta, colors.orange)
  2. local CLOSE = colors.white
  3. local IS_OPEN = colors.yellow
  4. local IS_CLOSED = colors.lightBlue
  5. local CABLE = "top"
  6. local LEVER = "right"
  7.  
  8. local function is_open()
  9.     return redstone.testBundledInput(CABLE, IS_OPEN)
  10. end
  11.  
  12. local function is_closed()
  13.     return redstone.testBundledInput(CABLE, IS_CLOSED)
  14. end
  15.  
  16. local function pulse_until(signal, fn)
  17.     repeat
  18.         redstone.setBundledOutput(CABLE, signal)
  19.         sleep(0.2)
  20.         redstone.setBundledOutput(CABLE, 0)
  21.         sleep(0.2)
  22.     until fn()
  23.     print "Done"
  24. end
  25.  
  26. while true do
  27.     local door_should_open = redstone.getInput(LEVER)
  28.     if door_should_open and not is_open() then
  29.         print "Opening"
  30.         pulse_until(OPEN, is_open)
  31.     elseif not door_should_open and is_closed then
  32.         print "Closing"
  33.         pulse_until(CLOSE, is_closed)
  34.     end
  35.     os.pullEvent "redstone"
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement