forked from blevinstein/cs3240
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RobotCommTest.java
42 lines (36 loc) · 1.22 KB
/
RobotCommTest.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
import java.io.*;
import lejos.nxt.*;
import lejos.nxt.comm.*;
// http://lejos.sourceforge.net/nxt/nxj/tutorial/Communications/Communications.htm
public class RobotCommTest {
public static void main(String[] args) {
while(true) {
LCD.drawString("Waiting...",0,0);
NXTConnection connection = Bluetooth.waitForConnection();
LCD.clear();
LCD.drawString("Connected",0,0);
DataInputStream dis = connection.openDataInputStream();
DataOutputStream dos = connection.openDataOutputStream();
for(int i=0; i<100; i++) {
try {
int n = dis.readInt();
LCD.drawInt(n, 7, 0, 1);
dos.writeInt(-n);
dos.flush();
} catch (IOException e) {
LCD.drawString("Loop exception",0,0);
}
}
try {
dis.close();
dos.close();
} catch (IOException e) {
LCD.drawString("Close exception",0,0);
}
LCD.clear();
LCD.drawString("Closing...",0,0);
connection.close();
LCD.clear();
}
}
}