Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local rs = component.redstone
- local gpu = component.gpu
- local event = require("event")
- local string = require("string")
- local lift_mon = "11e4d71b-9c75-4ed5-9576-f91d93a8f504"
- local lift_gpu = "194dd0b2-0a9e-4980-80e3-7d84ea9c90f2"
- local floor_gpu = "b20f1ae5-ebf1-40e2-a384-ec2319842644"
- local motors_side = require("sides").back
- local buttons_side = require("sides").front
- local buttons = {}
- buttons[241] = 1
- buttons[231] = 2
- buttons[221] = 3
- buttons[211] = 4
- buttons[201] = 5
- buttons[191] = 6
- local motors = {}
- motors["up"] = 0
- motors["down"] = 1
- motors["1open"] = 2
- motors["1close"] = 3
- motors["2open"] = 4
- motors["2close"] = 5
- motors["3open"] = 6
- motors["3close"] = 7
- motors["4open"] = 8
- motors["4close"] = 9
- motors["5open"] = 10
- motors["5close"] = 11
- motors["6open"] = 12
- motors["6close"] = 13
- local monitors = {}
- monitors[1] = "978fd6b3-c7fe-4341-b76a-5b895005edb1"
- monitors[2] = "770fe293-bfee-4066-bca2-e8fa9b6aea91"
- monitors[3] = "eb33d09f-1ef5-41b1-a602-06b8f099b811"
- monitors[4] = "b33e19f1-e1aa-4016-9d83-f0bb62571304"
- monitors[5] = "5872fbd2-5884-4286-a4bc-6232434724c2"
- monitors[6] = "f940e1bf-3d6a-47ce-8ed7-7f7dd89369b0"
- local up_sym = "▲"
- local down_sym = "▼"
- local lift_gpu = component.proxy(lift_gpu)
- local floor_gpu = component.proxy(floor_gpu)
- lift_gpu.bind(lift_mon)
- lift_gpu.setResolution(1,3)
- local function started(_, address)
- if address == lift_mon then
- a=true
- end
- end
- local function floor_info(cur_fl, dest_fl, updown)
- for _, addr in pairs(monitors) do
- floor_gpu.bind(addr)
- if updown ~= "clear" then
- floor_gpu.setResolution(3,3)
- floor_gpu.set(1,2,tostring(cur_fl))
- floor_gpu.set(2,2,"→")
- floor_gpu.set(3,2,tostring(dest_fl))
- end
- if updown == "up" then
- floor_gpu.set(1,1,up_sym)
- elseif updown == "down" then
- floor_gpu.set(1,3,down_sym)
- elseif updown == "clear" then
- floor_gpu.set(1,1," ")
- floor_gpu.set(1,3," ")
- floor_gpu.setResolution(1,1)
- floor_gpu.set(1,1,tostring(cur_fl))
- end
- end
- end
- local function start(floor_num, current_floor)
- print("Запуск лифта")
- print("Закрытие двери на "..current_floor.." этаже")
- rs.setBundledOutput(motors_side, motors[current_floor.."open"], 0)
- rs.setBundledOutput(motors_side, motors[current_floor.."close"], 255)
- os.sleep(3)
- a2b = (floor_num - current_floor)
- print("Отладочная информация: значение a2b = "..a2b)
- io.write("Направление: ")
- if string.sub(a2b,1,1) == "-" then
- print("вниз, "..floor_num.." этаж")
- floor_info(current_floor, floor_num, "down")
- a2b = string.sub(a2b, 2, string.len(a2b))
- for i=1, a2b do
- rs.setBundledOutput(motors_side, motors["down"], 255)
- os.sleep(10)
- rs.setBundledOutput(motors_side, motors["down"], 0)
- current_floor = current_floor-1
- floor_info(current_floor, floor_num)
- os.sleep(1)
- end
- else
- print("вверх, "..floor_num.." этаж")
- floor_info(current_floor, floor_num, "up")
- for i=1, a2b do
- rs.setBundledOutput(motors_side, motors["up"], 255)
- os.sleep(10)
- rs.setBundledOutput(motors_side, motors["up"], 0)
- current_floor = current_floor+1
- floor_info(current_floor, floor_num)
- os.sleep(1)
- end
- end
- floor_info(current_floor, floor_num, "clear")
- print("Прибыл к этажу "..floor_num)
- print("-------------")
- os.sleep(1)
- lift_gpu.bind(lift_mon)
- lift_gpu.setResolution(1,3)
- lift_gpu.setForeground(0x00FF00)
- lift_gpu.set(1,2,tostring(current_floor))
- rs.setBundledOutput(motors_side, motors[current_floor.."open"], 255)
- rs.setBundledOutput(motors_side, motors[current_floor.."close"], 0)
- return current_floor
- end
- print("Калибровка лифта")
- print("Закрытие дверей")
- for door=6, 2, -1 do
- rs.setBundledOutput(motors_side, motors[door.."open"], 0)
- rs.setBundledOutput(motors_side, motors[door.."close"], 255)
- end
- print("Спуск лифта")
- rs.setBundledOutput(motors_side, motors["down"], 255)
- event.listen("component_removed", started)
- os.sleep(0.5)
- if a==true then
- print("Ожидание спуска лифта")
- event.pull("component_added")
- print("Лифт спущен")
- else
- print("Спуск не требуется")
- end
- event.ignore("component_removed", started)
- rs.setBundledOutput(motors_side, motors["down"], 0)
- local current_floor = 1
- floor_num = current_floor
- print("Открытие нижней двери")
- rs.setBundledOutput(motors_side, motors["1close"], 0)
- rs.setBundledOutput(motors_side, motors["1open"], 255)
- os.sleep(3)
- print("Лифт готов к работе")
- print("-------------")
- floor_info(current_floor, _, "clear")
- lift_gpu.set(1,1,up_sym)
- lift_gpu.set(1,3,down_sym)
- lift_gpu.setForeground(0x00FF00)
- lift_gpu.set(1,2,tostring(current_floor))
- while true do
- ev, add, s, y, signal = event.pull()
- if ev == "touch" and add == lift_mon then
- lift_gpu.setForeground(0xFF0000)
- if y == 1 then
- if floor_num ~= 6 then
- floor_num = floor_num+1
- lift_gpu.set(1,2,tostring(floor_num))
- end
- elseif y == 3 then
- if floor_num ~= 1 then
- floor_num = floor_num-1
- lift_gpu.set(1,2,tostring(floor_num))
- end
- elseif y == 2 then
- if current_floor ~= floor_num then
- current_floor = start(floor_num, current_floor)
- else
- lift_gpu.setResolution(1,3)
- lift_gpu.setForeground(0x00FF00)
- lift_gpu.set(1,2,tostring(current_floor))
- end
- end
- elseif ev == "redstone_changed" and s == buttons_side then
- fl = buttons[signal]
- --if fl ~= current_floor then
- print("Вызов на этаж "..fl)
- current_floor = start(fl, current_floor)
- floor_num = current_floor
- --end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement