-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenderbot2.java
71 lines (51 loc) · 1.64 KB
/
benderbot2.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import lejos.nxt.*;
import lejos.robotics.navigation.DifferentialPilot;
public class backandfourth //make sure the classname matches the filename (case-sensitive)
{
private DifferentialPilot bot; //field declaration for a DifferentialPilot object
//the code in the main method will not change (except for the classname)
public static void main(String[] args)
{
backandfourth myProgram = new backandfourth(); //matches classname (case-sensitive)
myProgram.run();
}//main()
//the constructor generally instantiates field objects and sets other initial state information
public backandfourth() //matches classname (case-sensitive)
{
bot = new DifferentialPilot(50, 50, Motor.B, Motor.C); //instantiate a DifferentialPilot object named "bot"
}//constructor
//your code goes in this method
public void run()
{
bot.travel(1524);
bot.rotate(370);
bot.travel(1524);
bot.stop();
}//run()
//the following method writes a string to the screen. Useful for debugging.
public void displayString(String msg)
{
LCD.clear();
LCD.drawString(msg, 0, 0); //writes the msg to the screen
LCD.refresh();
}//displayString()
//the following method writes an int (whole number) to the screen. Useful for debugging.
public void displayInt(int num)
{
LCD.clear();
LCD.drawInt(num, 4, 0, 0); //writes the num to the screen
LCD.refresh();
} //displayInt
//the following method allows the bot to do what it was doing, but suspends execution of the
//next statement. When this method returns, the program continues executing where it left off.
public void pause(int milli)
{
try
{
Thread.sleep(milli);
}//try
catch(InterruptedException e)
{
}//catch
}//sleep()
}//class backandfourth