O'Reilly logo

Lego Mindstorms EV3 Essentials by Abid H. Mujtaba

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The touch sensor

We use the touch sensor to learn how LeJOS handles sensors. Our aim is to set up the sensor and detect when the touch sensor is pressed. Once again, the first step is to set up the project structure with the root folder named Touch:

Touch
    | ---- src
              | ---- Touch.java
       | ---- TouchSensor.java
    | ---- build.gradle
    | ---- ev3
       | ---- DBusJava
       | ---- ev3classes

The build.gradle file is set up as usual with the main class named Touch after both the root folder name and the Touch class (inside the Touch.java file), which contains the main() function where the execution starts.

The TouchSensor.java file

LeJOS treats EV3 sensors in a consistent and generalized fashion. This means that the class for each EV3 sensor implements a fetchSample() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required