Crazybrain23

CC Redstone Controller

Nov 13th, 2022
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | Source Code | 0 0
  1. -- Author: crazybrain
  2. -- Date: 09/11/2022
  3. -- License: GPL v3.0
  4. -- Version: 1.0 (13/11/2022)
  5.  
  6. -- Function definitions
  7. function rsControl(side, colour, pulse, time)
  8.     pulse = pulse or false
  9.     time = time or 0
  10.     colour = colors[colour]
  11.     current = rs.getBundledOutput(side)
  12.     currentPlus = colors.combine(current, colour)
  13.     currentMinus = colors.subtract(current, colour)
  14.  
  15.     if pulse then
  16.         rs.setBundledOutput(side, currentPlus)
  17.         sleep(time)
  18.         rs.setBundledOutput(side, currentMinus)
  19.     else
  20.         if current == currentPlus then
  21.             rs.setBundledOutput(side, currentMinus)
  22.         else
  23.             rs.setBundledOutput(side, currentPlus)
  24.         end
  25.     end
  26. end
  27.    
  28. -- Visuals
  29. term.clear()
  30. term.setCursorPos(1,1)
  31. print("1    Main Door")
  32. print("2    Maintenance Door")
  33. term.setCursorPos(1, 10)
  34. print("q    Quit")
  35.  
  36. -- Main loop
  37. while true do
  38.     --grabs the key inputs from
  39.     _, eventInput = os.pullEvent("char")    
  40.  
  41.     if     eventInput == "q" then
  42.         print("Program Quiting...")
  43.         break
  44.        
  45.     elseif eventInput == "1" then
  46.         rsControl("back", "red", true, 1)
  47.        
  48.     elseif eventInput == "2" then
  49.         -- Maintenance Door
  50.         rsControl("left", "white")
  51.        
  52.     end
  53. end
Add Comment
Please, Sign In to add comment