1. Introduction

Create your first project is not complicated, for that action, exist 2 alternatives:

  • Create your project from a Template Project

  • Create your project from Scratch

2. Create your first project with a Gradle template project

The project provide a Gradle template project ready to run in your favourite Java IDE.

Visit this Git repository to download the project:

git clone https://github.com/ev3dev-lang-java/template_project_gradle.git

Once you have downloaded the project in your personal computer, open the project with your Java IDE to edit the file: config.gradle: to update IP of you Brick:

remotes {
    ev3dev {
        host = '10.0.1.3'
        user = 'robot'
        password = 'maker'
    }
}

The project are configured to send to the Brick the following example:

package examples;

import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
import ev3dev.sensors.Battery;
import lejos.hardware.port.MotorPort;
import lejos.utility.Delay;

public class MyFirstRobot {

    public static void main(final String[] args){

        System.out.println("Creating Motor A & B");
        final EV3LargeRegulatedMotor motorLeft = new EV3LargeRegulatedMotor(MotorPort.A);
        final EV3LargeRegulatedMotor motorRight = new EV3LargeRegulatedMotor(MotorPort.B);

        //To Stop the motor in case of pkill java for example
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            public void run() {
                System.out.println("Emergency Stop");
                motorLeft.stop();
                motorRight.stop();
            }
        }));

        System.out.println("Defining the Stop mode");
        motorLeft.brake();
        motorRight.brake();

        System.out.println("Defining motor speed");
        final int motorSpeed = 200;
        motorLeft.setSpeed(motorSpeed);
        motorRight.setSpeed(motorSpeed);

        System.out.println("Go Forward with the motors");
        motorLeft.forward();
        motorRight.forward();

        Delay.msDelay(2000);

        System.out.println("Stop motors");
        motorLeft.stop();
        motorRight.stop();

        System.out.println("Go Backward with the motors");
        motorLeft.backward();
        motorRight.backward();

        Delay.msDelay(2000);

        System.out.println("Stop motors");
        motorLeft.stop();
        motorRight.stop();

        System.out.println("Checking Battery");
        System.out.println("Votage: " + Battery.getInstance().getVoltage());

        System.exit(0);
    }
}

The example was designed to move a mobile robot with 2 motors connected to Port A & Port B.

2.1. Deploy your program

To deploy the example on your brick, open a terminal and type:

./gradlew deployAndRun

3. Create your first project from scratch

Another alternative is the creation of a project from Scratch using Maven/Gradle.

To start a new project with this library, add the following repository and dependency.

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependency>
    <groupId>com.github.ev3dev-lang-java</groupId>
    <artifactId>ev3dev-lang-java</artifactId>
    <version>v0.6.1</version>
</dependency>

Further information about the dependency

4. Playing with more examples

The project has a repository with several examples about the usage of the different libraries.

Visit the repository about examples to download and test more examples.