Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local machine = {
- width = 8,
- height = 8,
- depth = 8,
- head_pos = {
- x = 0,
- y = 0,
- z = 0
- },
- motorz = peripheral.wrap("top"),
- motorx = peripheral.wrap("left"),
- motory = peripheral.wrap("back")
- }
- rednet.open("right")
- function machine.stopMotion()
- machine.motorz.stop()
- machine.motorx.stop()
- machine.motory.stop()
- end
- function machine.zero()
- sleep(machine.motorx.translate(machine.width, 256))
- machine.stopMotion()
- sleep(machine.motory.translate(machine.depth, 256))
- machine.stopMotion()
- sleep(machine.motorz.translate(machine.height, 256))
- machine.stopMotion()
- machine.head_pos.x = 0
- machine.head_pos.y = 0
- machine.head_pos.z = 0
- end
- function machine.setX(x)
- local x_difference = machine.head_pos.x - x
- print("Moving x by " .. x_difference .. " from " .. machine.head_pos.x.." to " ..x)
- sleep(machine.motorx.translate(x_difference, 256))
- machine.stopMotion()
- machine.head_pos.x = x
- end
- function machine.setZ(z)
- local z_difference = machine.head_pos.z - z
- print("Moving z by ".. z_difference .. " from "..machine.head_pos.z.." to "..z)
- sleep(machine.motorz.translate(z_difference, 128))
- machine.stopMotion()
- machine.head_pos.z = z
- end
- function machine.setY(y)
- local y_difference = machine.head_pos.y - y
- print("Moving y by ".. y_difference .. " from " .. machine.head_pos.y.." to " .. y)
- sleep(machine.motory.translate(y_difference, 256))
- machine.stopMotion()
- machine.head_pos.y = y
- end
- function machine.setPos(x, y, z)
- machine.setZ(z)
- sleep(0.25)
- machine.setX(x)
- sleep(0.25)
- machine.setY(y)
- end
- function machine.placeBlock()
- sleep(0.5)
- rednet.broadcast("place", "3dprinter")
- while true do
- event, sender, message, protocol = os.pullEvent("rednet_message")
- if protocol == "3dprinter" and message == "placed" then
- break
- end
- end
- end
- machine.stopMotion()
- machine.zero()
- return machine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement