Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function main()
- local monitor_pos = args[4]
- init(monitor_pos)
- while true do
- local pin = ""
- for i = 1, 4 do
- -- Get input from monitor.
- local input = get_input()
- if input ~= nil then
- monitor = peripheral.wrap(input[2])
- pin = pin .. input[1]
- redstone.setAnalogOutput(sound_pos, 15)
- sleep(0.1)
- redstone.setAnalogOutput(sound_pos, 0)
- sleep(0.1)
- end
- end
- -- Check if code is right.
- if pin == correct_pin then
- -- Send redstone signal for (seconds).
- monitor.setBackgroundColor(32)
- monitor.clear()
- redstone.setAnalogOutput(redstone_pos, 15)
- sleep(4)
- redstone.setAnalogOutput(redstone_pos, 0)
- else
- sleep(0.2)
- for i = 1, 2 do
- monitor.setBackgroundColor(16384)
- monitor.clear()
- redstone.setAnalogOutput(sound_pos, 15)
- sleep(0.1)
- redstone.setAnalogOutput(sound_pos, 0)
- sleep(0.1)
- end
- end
- monitor.setBackgroundColor(32768)
- monitor.clear()
- end
- end
- function get_input()
- monitor.setTextScale(1.5)
- monitor.clear()
- term.clear()
- monitor.setBackgroundColor(4096)
- monitor.setCursorPos(2,1)
- monitor.write("789")
- monitor.setCursorPos(2,2)
- monitor.write("456")
- monitor.setCursorPos(2,3)
- monitor.write("123")
- monitor.setBackgroundColor(32768)
- local event, side, x, y = os.pullEvent()
- if event == "monitor_touch" then
- if x == 2 and y == 1 then
- return { "7", side }
- elseif x == 3 and y == 1 then
- return { "8", side }
- elseif x == 4 and y == 1 then
- return { "9", side }
- elseif x == 2 and y == 2 then
- return { "4", side }
- elseif x == 3 and y == 2 then
- return { "5", side }
- elseif x == 4 and y == 2 then
- return { "6", side }
- elseif x == 2 and y == 3 then
- return { "1", side }
- elseif x == 3 and y == 3 then
- return { "2", side }
- elseif x == 4 and y == 3 then
- return { "3", side }
- end
- end
- return nil
- end
- function init(monitor_pos)
- monitor = peripheral.wrap(monitor_pos)
- end
- args = {...}
- correct_pin = args[1]
- redstone_pos = args[2]
- sound_pos = args[3]
- monitor = nil
- coroutine.yield()
- main()
Advertisement
Comments
-
- Start-parameters needed:
- 1. (string) PIN
- 2. (string) Redstone Signal Side (On Correct PIN)
- 3. (string) Nodeblock Side
- 4. (string) Monitor Side
Add Comment
Please, Sign In to add comment
Advertisement