View difference between Paste ID: aMcWpRjY and LrJFyZ9H
SHOW: | | - or go back to the newest paste.
1
local t = turtle
2
3
local function forward(x)
4
	for i = 1, x do
5
		t.forward()
6
	end
7
end
8
9
local function rTurn(x)
10
	for i = 1, x do
11
		t.turnRight()
12
	end
13
end
14
15
local function lTurn(x)
16
	for i = 1, x do
17
		t.turnLeft()
18
	end
19
end
20
21
local function up(x)
22
	for i = 1, x do
23
		t.up()
24
	end
25
end
26
27
local function down(x)
28
	for i = 1, x do
29
		t.down()
30
	end
31
end
32
33
local function back(x)
34
	for i = 1, x do
35
		t.back()
36
	end
37
end
38
39
local function gotoStart()
40
	rs.setAnalogOutput("left", 0)
41
	os.sleep(1)
42
	up(2)
43
	back(1)
44
	lTurn(1)
45
	forward(1)
46
end
47
48
local function rowUp()
49
	for i = 1, 1, 4 do
50
		t.dig()
51
		up(1)
52
	end
53
end
54
55
local function rowDown()
56
	for i = 1, 1, 4 do
57
		t.dig()
58
		down(1)
59
	end
60
end
61
62
local facing = t.detect()
63
64
local height = t.detect(down)
65
66
local function harvest(x)
67
	for i = 1, x do
68
		rTurn(1)
69
		if facing == true then
70
			if height == true then
71
				rowUp()
72
			else
73
				rowDown()
74
			end
75
		else if facing == false then
76
			forward(1)
77
			lTurn(1)
78
				if height == true then
79
					rowUp()
80
				else
81
					rowDown()
82
				end
83
		end
84
	end
85
end
86
87
local function gotoHome()
88
	back(2)
89
	lTurn(1)
90
	forward(1)
91
	down(5)
92
	os.sleep(1)
93
	rs.setAnalogOutput("left", 15)
94
	os.sleep(3600)
95
end
96
97
while true do	
98
	gotoStart()
99
	rowUp()
100
	harvest(6)
101
	gotoHome()
102
end