-
Notifications
You must be signed in to change notification settings - Fork 0
/
FollowLine.java
35 lines (27 loc) · 912 Bytes
/
FollowLine.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// package *add package name here*;
import lejos.hardware.Button;
import lejos.utility.Delay;
public class FollowLine extends EV3Skeleton {
/**
* Main function of program.
*/
public static void main(String[] args) {
initRobot();
initPilot();
System.out.println("Press any button to start!");
Button.waitForAnyPress();
// Add your code below here
double lineThreshold = 0.35;
while(true) {
if (colorSensor.getReflectedRed() < lineThreshold) {
// On line, turn sharply to the left
pilot.arcForward(0.05);
} else {
// Off line, turn slightly to the right
pilot.arcForward(-0.2);
}
// A bit of delay to allow the robot time to move
Delay.msDelay(100);
}
}
}