Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --setup : rope pulley, monitor in elevator connected by wired network, motor direct force to pulley, advanced computer
- engine = peripheral.find("electric_motor")
- monitor = peripheral.find("monitor")
- modem = peripheral.find( "modem" )
- modem.open(420)
- position = 0 --current position
- speed = 128 --normal speed
- block = 152.5 --degree per block
- floors = {} --floors table
- fcount = 0 --amount of floors
- function startElevator()
- height = 256
- engine.setSpeed(256)
- print("Setting up elevator, its gonna take " .. engine.rotate(256 * block) .. " seconds.")
- monitor.setBackgroundColor(colors.red)
- monitor.setTextColor(colors.white)
- monitor.clear()
- monWrite("Setting",1,2)
- monWrite("things",1,3)
- monWrite("up...",2,4)
- sleep(engine.rotate(block * height))
- position = 0
- engine.stop()
- print("position = 0")
- sleep(1)
- print("Everything set up.")
- end
- function setPos(pos)
- vec = pos - position
- speedTemp = 1
- if vec > 0 then
- speedTemp = -speed
- elseif vec < 0 then
- speedTemp = speed
- else
- speedTemp = 0
- end
- --print("Vector : " .. math.abs(vec) - slow - superslow)
- engine.setSpeed(speedTemp)
- sleep(engine.rotate(block * math.abs(vec)))
- engine.stop()
- print("Pos: " .. position .. " to pos: " .. position + vec)
- position = position + vec
- end
- function addFloor(y)
- print("Floor " .. fcount .. " set to " .. y .. " block.")
- floors[fcount] = y
- fcount = fcount + 1
- end
- function goFloor(fnumber)
- setPos(floors[fnumber])
- print("Going to floor " .. fnumber .. " block " .. floors[fnumber] .. ".")
- end
- function clearFloors()
- for i = 0,fcount,1 do
- floors[i] = nil
- end
- print("Floors cleared from ram.")
- end
- function saveFloors()
- local savefile = fs.open("floors","w")
- for i = 0,fcount - 1,1 do
- if floors[i] ~= nil then
- savefile.writeLine(floors[i])
- end
- end
- savefile.close()
- print("Floors saved.")
- end
- function loadFloors()
- local savefile = fs.open("floors","r")
- local line = "hehepenis"
- fcount = 0
- while line ~= nil do
- line = savefile.readLine()
- if line ~= nil then
- floors[fcount] = tonumber(line)
- print("Floor " .. fcount .. " block " .. line .. " added.")
- fcount = fcount + 1
- end
- end
- savefile.close()
- print("Floors loaded.")
- end
- function monWrite(str,x,y)
- if monitor then
- monitor.setCursorPos(x, y)
- monitor.write(str)
- end
- end
- function monitorStart()
- if monitor then
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- monitor.setBackgroundColor(colors.white)
- monitor.setTextColor(colors.black)
- monitor.setCursorBlink(false)
- for i = 0 , fcount - 1,1 do
- --print(i)
- if i+1 <= 5 then
- monWrite(tostring(i),3,i+1)
- elseif i+1 > 5 and i+1 < 10 then
- monWrite(tostring(i),5,i+1-5)
- end
- end
- end
- end
- function monitorPress(x,y)
- for i = 0,fcount - 1,1 do
- if x == 3 and y == i+1 then
- monWrite("X",3,i+1)
- goFloor(i)
- elseif x == 5 and y == i+1-5 then
- monWrite("X",5,i+1-5)
- goFloor(i)
- end
- end
- end
- function main()
- loadFloors()
- saveFloors()
- startElevator()
- while true do
- sleep(0.5)
- monitorStart()
- event, side, xPos, yPos, message = os.pullEvent()
- if event == "monitor_touch" then
- monitorPress(xPos,yPos)
- elseif event == "modem_message" then
- goFloor(message)
- end
- end
- end
- main()
Add Comment
Please, Sign In to add comment