Advertisement
NekoLogi

door_lock.lua

Oct 13th, 2022 (edited)
170
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | Source Code | 0 0
  1. function main()
  2.     local monitor_pos = args[4]
  3.     init(monitor_pos)
  4.     while true do
  5.         local pin = ""
  6.         for i = 1, 4 do
  7.             -- Get input from monitor.
  8.             local input = get_input()
  9.  
  10.             if input ~= nil then
  11.                 monitor = peripheral.wrap(input[2])
  12.                 pin = pin .. input[1]
  13.                 redstone.setAnalogOutput(sound_pos, 15)
  14.                 sleep(0.1)
  15.                 redstone.setAnalogOutput(sound_pos, 0)
  16.                 sleep(0.1)
  17.             end
  18.         end
  19.         -- Check if code is right.
  20.         if pin == correct_pin then
  21.             -- Send redstone signal for (seconds).
  22.             monitor.setBackgroundColor(32)
  23.             monitor.clear()
  24.             redstone.setAnalogOutput(redstone_pos, 15)
  25.             sleep(4)
  26.             redstone.setAnalogOutput(redstone_pos, 0)
  27.         else
  28.             sleep(0.2)
  29.             for i = 1, 2 do
  30.                 monitor.setBackgroundColor(16384)
  31.                 monitor.clear()
  32.                 redstone.setAnalogOutput(sound_pos, 15)
  33.                 sleep(0.1)
  34.                 redstone.setAnalogOutput(sound_pos, 0)
  35.                 sleep(0.1)
  36.             end
  37.         end
  38.         monitor.setBackgroundColor(32768)
  39.         monitor.clear()
  40.     end
  41. end
  42.  
  43. function get_input()
  44.     monitor.setTextScale(1.5)
  45.     monitor.clear()
  46.     term.clear()
  47.     monitor.setBackgroundColor(4096)
  48.     monitor.setCursorPos(2,1)
  49.     monitor.write("789")
  50.     monitor.setCursorPos(2,2)
  51.     monitor.write("456")
  52.     monitor.setCursorPos(2,3)
  53.     monitor.write("123")
  54.     monitor.setBackgroundColor(32768)
  55.     local event, side, x, y = os.pullEvent()
  56.     if event == "monitor_touch" then
  57.         if x == 2 and y == 1 then
  58.             return { "7", side }
  59.         elseif x == 3 and y == 1 then
  60.             return { "8", side }
  61.         elseif x == 4 and y == 1 then
  62.             return { "9", side }
  63.         elseif x == 2 and y == 2 then
  64.             return { "4", side }
  65.         elseif x == 3 and y == 2 then
  66.             return { "5", side }
  67.         elseif x == 4 and y == 2 then
  68.             return { "6", side }
  69.         elseif x == 2 and y == 3 then
  70.             return { "1", side }
  71.         elseif x == 3 and y == 3 then
  72.             return { "2", side }
  73.         elseif x == 4 and y == 3 then
  74.             return { "3", side }
  75.         end
  76.     end
  77.     return nil
  78. end
  79.  
  80. function init(monitor_pos)
  81.     monitor = peripheral.wrap(monitor_pos)
  82. end
  83.  
  84.  
  85. args = {...}
  86. correct_pin = args[1]
  87. redstone_pos = args[2]
  88. sound_pos = args[3]
  89. monitor = nil
  90. coroutine.yield()
  91.  
  92. main()
Advertisement
Comments
  • NekoLogi
    1 year
    # text 0.14 KB | 0 0
    1. Start-parameters needed:
    2. 1. (string) PIN
    3. 2. (string) Redstone Signal Side (On Correct PIN)
    4. 3. (string) Nodeblock Side
    5. 4. (string) Monitor Side
Add Comment
Please, Sign In to add comment
Advertisement