Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Pastebin code: Eps1arN4
- --local bundleSide = "right"
- local modem = peripheral.wrap("top")
- local mon = peripheral.wrap("bottom")
- local mX, mY = mon.getSize()
- mon.setTextScale(1)
- mon.setTextColor(colors.white)
- local button={}
- mon.setBackgroundColor(colors.black)
- liftControl = 32
- function MoveUp( dist )
- rednet.send(liftControl, "up")
- local id, message, distance = rednet.receive(5)
- if id == liftControl then
- if message == "ok" then
- rednet.send(liftControl, tostring(dist))
- id, message, distance = rednet.receive()
- end
- end
- end
- function MoveDown()
- rednet.send(liftControl, "down")
- local id, message, distance = rednet.receive(5)
- if id == liftControl then
- if message == "ok" then
- rednet.send(liftControl, tostring(dist))
- id, message, distance = rednet.receive()
- end
- end
- end
- function checkxy(x, y)
- local activeFunc = "none"
- print(x.." "..y)
- for name, data in pairs(button) do
- if y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- data["active"] = not data["active"]
- activeFunc = name
- print(name)
- end
- end
- end
- if (activeFunc ~= "none") then
- button[activeFunc]["func"]()
- end
- end
- function fill(text, color, bData)
- mon.setBackgroundColor(color)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- mon.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- mon.write(text)
- else
- mon.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- function CreateButton(name, func, minX, minY, maxX, maxY)
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = minX
- button[name]["ymin"] = minY
- button[name]["xmax"] = maxX
- button[name]["ymax"] = maxY
- end
- function SetUpButtons()
- CreateButton("Sec", Top, 3, 2, 5, 3)
- CreateButton("B", Basement, 2, 11, 3, 12)
- CreateButton("LB", LowerBasement, 5, 11, 6, 12)
- CreateButton("G", Ground, 2, 9, 3, 10)
- CreateButton("1", FirstFloor, 5, 9, 6, 10)
- end
- function MoveLift(level)
- local x, z, y = gps.locate()
- print("destination.."..level)
- print("start.."..y)
- if y == level then
- --do nothing as on right floor
- elseif y < level then
- --while y ~= level do
- MoveUp(level - y)
- x, z, y = gps.locate()
- print("up.."..y)
- --end
- elseif y > level then
- --while y ~= level do
- MoveDown(y - level)
- x, z, y = gps.locate()
- print("down.."..y)
- --end
- end
- end
- function Top()
- print("Top")
- local level = 152
- MoveLift(level)
- end
- function Basement()
- print("B")
- local level = 66
- MoveLift(level)
- end
- function LowerBasement()
- print("LB")
- local level = 51
- MoveLift(level)
- end
- function Ground()
- print("G")
- local level = 77
- MoveLift(level)
- end
- function FirstFloor()
- print("1")
- local level = 83
- MoveLift(level)
- end
- function Screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- if on == true then
- currColor = colors.lime
- else currColor = colors.red
- end
- fill(name, currColor, data)
- end
- end
- SetUpButtons()
- while true do
- mon.clear()
- Screen()
- local event, side, x, y = os.pullEvent()
- if event == "monitor_touch" then
- print("event: "..event)
- checkxy(x, y)
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement