This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Jackozzy's profile picture

Multi-floor elevator with Redstone in Motion

Started by Jackozzy, 02 April 2016 - 01:31 AM
Jackozzy #1
Posted 02 April 2016 - 03:31 AM
I'm relatively new to computer craft and coding in general so I have no idea what I'm doing. I'm trying to build a multi-floor elevator in my factory using Redstone in Motion carriages. I want to know if there is a way for me to write a command or press a button and have the carriage move to a specific floor through the computer. I've been reading through wiki's and watching walkthroughs but I either don't understand them or they don't cover what I need. I would really appreciate if someone could help me figure this out.
Unknowntissue #2
Posted 02 April 2016 - 05:27 PM
I have actually already made this in one of my worlds. It can turn into quite the monster in terms of how you wire it. You will need to use bundled wires not sure if you have them in your mod pack but if you are using tekkit then you should.

For each floor, I had a redstone signal that would go to the computer to tell it the elevator was on that floor. I did this by adding a redstone block to elevator that would land inline with a wire once it reached the floor.

Now that you have a way of reading what floor its on you just have to program how many moves you have to go to reach the goal. I think on my example it was 4 block per floor so if i need to go down 2 floors i moved down 8 times.

If you didn't know, you will be needing this link allot. http://www.computercraft.info/wiki/Redstone_(API)

If you want to eliminate some wire i would also look here. http://www.computercraft.info/wiki/Rednet_(API)
P.S: Don't use the rednet if you having to much of a hard time with computercraft it will complicate your code a bit.
Unknowntissue #3
Posted 02 April 2016 - 06:44 PM
I actually found the code for the program i did. I was very new to programming when i made this so take it with a grain of salt…. but it does work. Maybe you can improve on it or just use it.

It works by using a computer on each floor to act like a terminal. Then it will send a wireless rednet signal to the computer controlling the motors. Also keep in mind that is was made to work on a 2 floor building only. You need to improve it a bit if you want more.

this is the code for the terminal: Edit:This terminal is for the top floor
Spoiler

--#oooooooooo start oooooooooooo
rednet.open("top")
run = true
term.clear()
w,h = term.getSize()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
xpos = 1
ypos = 1
local floor = 2
--#oooooooooooooooooooooooooooo
function printCent(n)
  xpos, ypos = term.getCursorPos()
  local length = string.len(n)
  term.setCursorPos((w/2)-(length/2),ypos)
  term.write(n)
  end
function user()
  term.clear()
  term.setCursorPos(1,1)
  term.setBackgroundColor(colors.black)
  printCent("Welcome User")
  term.setCursorPos(1,2)
  for i=1,w do term.write("-") end
  term.setCursorPos(1,5)
  term.setBackgroundColor(colors.white)
  term.setTextColor(colors.black)
  printCent("  UP  ")
  term.setCursorPos(1,8)
  printCent(" DOWN ")
  term.setBackgroundColor(colors.black)
  term.setTextColor(colors.white)


  event,button, cxpos, cypos = os.pullEvent("mouse_click")
  if cxpos >=22 and cxpos <= 27 and cypos == 8 then
	if redstone.getInput("left") == true then
	  term.clear()
	  term.setCursorPos(1,1)
	  print(" Already on this Floor")
	  os.sleep(2)
	else
	  rednet.send(13,"down")
	end
  elseif cxpos >=22 and cxpos <= 27 and cypos == 5 then
	if redstone.getInput("back") == true then

	else
	  rednet.send(13,"up")
	  print("down")
	end	
  end
end
local stat = true
while stat == true do
user()
end
This the code for the computer controlling the motors:
Spoiler

--#ooooooooooo startup ooooooooooooo
drive = peripheral.wrap("back")
run = true
rednet.open("right")
--#oooooooooooooooooooooooooooooooo
function move(n,d)
  for i = 1,n do
	redstone.setOutput(d,true)

	os.sleep(1)
	redstone.setOutput(d,false)
	os.sleep(1)
  end
  redstone.setOutput(d,false)
end
while run == true do
local event, dist , msg = os.pullEvent()
  if event == "rednet_message" then
	print(event)

	if msg == "down"then

	 move(5,"top")
	
	elseif msg == "up" then
	  move(5,"bottom")
	end

  elseif event == "char" and dist == "x" then
	print("Ending")
	run = false

  end
end

I wish got into the habit of adding more comments when i made this but if you have any questions about it you can just ask and I'm sure i can work it out.
Edited on 02 April 2016 - 05:09 PM