Posted 23 March 2013 - 07:05 AM
I am creating an elevator using Frames & Frame Motors and trying to control it all by using computers. I have a house that is 3 floors, a roof, and a basement – each with 4 blocks between. I have written functions for moveUp and moveDown (code below). Now I am trying to make a callElevator function to make the elevator rise or fall to your current floor. I am trying to bundle this into an API as well. The code I have written already is saved as elevatorAPI on a floppy disk:
– Note, 0 blocks = basement,
4 blocks = ground floor
8 blocks = 2nd floor
12 blocks = 3rd floor
16 blocks = roof
– will use in the code
I have the exact same code written for the moveDown() function except with the obvious changes to make the elevator descend. Now, I am trying to find a way to make a callElevator() function and tried for 4 hours last night until I passed out. I am seeking guidance, not necessarily someone writing it for me at all.
Also, note I have a computer set up at the elevator door on each floor all connected to the same cables to the same motor. Need any more information I will gladly present it. Please help! Also, I accept any optimization tips. I am trying to learn to program as best I can.
– Note, 0 blocks = basement,
4 blocks = ground floor
8 blocks = 2nd floor
12 blocks = 3rd floor
16 blocks = roof
– will use in the code
function moveUp()
side = "left" -- denotes the side where the cables are attached
color = colors.orange -- orange cable activates UP motor
currentBlocks = 1 -- Number of blocks ranging from 16 to 0 to denote position of elevator
floor = tonumber(io.read())
floors = floor * 4 --used in for loop
if floors > 14 then -- prevents elevator from raising off the motors
for i=currentBlocks, 14 do
rs.setBundledOutput(side, color)
sleep(1)
rs.setBundledOutput(side, 0)
sleep(1)
end
else
for i=currentBlocks, floors do
rs.setBundledOutput(side, color)
sleep(1)
rs,setBundledOutput(side, 0)
sleep(1)
end
end
end
I have the exact same code written for the moveDown() function except with the obvious changes to make the elevator descend. Now, I am trying to find a way to make a callElevator() function and tried for 4 hours last night until I passed out. I am seeking guidance, not necessarily someone writing it for me at all.
Also, note I have a computer set up at the elevator door on each floor all connected to the same cables to the same motor. Need any more information I will gladly present it. Please help! Also, I accept any optimization tips. I am trying to learn to program as best I can.