Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.AJD1.bluetoothrc;
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.net.ServerSocket;
- import java.net.Socket;
- import lejos.hardware.Sound;
- import lejos.hardware.motor.EV3LargeRegulatedMotor;
- import lejos.hardware.port.MotorPort;
- public class BluetoothRCServer {
- public static void main(String args[]) throws IOException {
- int input;
- ServerSocket server = new ServerSocket(1111);
- EV3LargeRegulatedMotor motorA = new EV3LargeRegulatedMotor(MotorPort.A);
- EV3LargeRegulatedMotor motorB = new EV3LargeRegulatedMotor(MotorPort.B);
- IsEscapeDownChecker isEscapeDownChecker = new IsEscapeDownChecker(server);
- isEscapeDownChecker.setDaemon(true);
- isEscapeDownChecker.start();
- while (true) {
- Socket socket;
- try {
- socket = server.accept();
- } catch (IOException e) {
- break;
- }
- DataInputStream in = new DataInputStream(socket.getInputStream());
- input = in.readInt();
- if (input == 1) {
- motorA.forward();
- motorB.forward();
- }
- if (input == 2) {
- motorA.backward();
- motorB.backward();
- }
- if (input == 3) {
- motorA.backward();
- motorB.forward();
- }
- if (input == 4) {
- motorA.forward();
- motorB.backward();
- }
- if (input == 5) {
- motorA.stop();
- motorB.stop();
- }
- if (input == 6) {
- Sound.setVolume(100);
- Sound.buzz();
- server.close();
- motorA.close();
- motorB.close();
- System.exit(0);
- }
- if (input == 7) {
- Sound.setVolume(100);
- Sound.beep();
- }
- }
- Sound.setVolume(100);
- Sound.buzz();
- server.close();
- motorA.close();
- motorB.close();
- System.exit(0);
- }
- }
Add Comment
Please, Sign In to add comment