import java.io.DataInputStream; import java.io.DataOutputStream; import lejos.nxt.LCD; import lejos.nxt.MotorPort; import lejos.nxt.comm.BTConnection; import lejos.nxt.comm.Bluetooth; public class BTReceiverP { public static void main(String[] args) throws Exception { Bluetooth.setFriendlyName(BTUtils.stringToByteName(BTUtils.RECEIVER_NAME)); MotorPort speaker = MotorPort.A; String connected = "Connected"; String waiting = "Waiting"; LCD.drawString(waiting, 0, 0); LCD.refresh(); BTConnection btc = Bluetooth.waitForConnection(); LCD.clear(); LCD.drawString(connected, 0, 0); LCD.refresh(); DataInputStream dis = new DataInputStream(btc.openInputStream()); DataOutputStream dos = new DataOutputStream(btc.openOutputStream()); while (true) { int x = dis.readByte(); speaker.controlMotor(x * 10, 1); dos.writeByte((byte) 0xFF); // Ack dos.flush(); LCD.drawInt(x, 4, 0, 1); LCD.refresh(); } } }