OSDN Git Service

9482fd37d92f3c72a814699e35811fb459699f08
[nxt-jsp/lejos_nxj.git] / nxtOSEK / lejos_nxj / samples / BTReceive / BTReceive.java
1 import lejos.nxt.*;
2 import lejos.nxt.comm.*;
3 import java.io.*;
4
5 public class BTReceive {
6
7         public static void main(String [] args)  throws Exception 
8         {
9                 String connected = "Connected";
10         String waiting = "Waiting";
11
12                 while (true)
13                 {
14                         LCD.drawString(waiting,0,0);
15                         LCD.refresh();
16
17                 BTConnection btc = Bluetooth.waitForConnection();
18                 
19                         LCD.clear();
20                         LCD.drawString(connected,0,0);
21                         LCD.refresh();  
22                         
23                         InputStream is = btc.openInputStream();
24                         OutputStream os = btc.openOutputStream();
25                         DataInputStream dis = new DataInputStream(is);
26                         DataOutputStream dos = new DataOutputStream(os);
27                         
28                         for(int i=0;i<100;i++) {
29                                 int ii = dis.readInt();
30                                 LCD.drawInt(ii,3,0,1);
31                                 LCD.refresh();
32                                 dos.writeInt(-ii);
33                                 dos.flush();
34                         }
35                         
36                         dis.close();
37                         dos.close();
38                         btc.close();
39                         LCD.clear();
40                 }
41         }
42 }
43