Main Content

readTouch

Read touch sensor value

Add-On Required: This feature requires the MATLAB Support Package for LEGO MINDSTORMS EV3 Hardware add-on.

Description

pressed = readTouch(mytouchsensor) reads whether an object is pressing the front of the touch sensor, and returns the status as a logical value:

  • 0 means not pressed.

  • 1 means pressed.

example

Examples

collapse all

Determine whether an object is pressing the touch sensor.

Create a connection to the EV3 brick called myev3.

myev3 = legoev3
myev3 = 

  legoev3 with properties:

      FirmwareVersion: 'V1.03E'
           HardwareID: []
            IPAddress: []
    CommunicationType: 'USB'
         BatteryLevel: 100
     ConnectedSensors: {'touch'  'gyro'  'color'  'sonic'}

The sensor appears in the list of connected sensors.

Connect to a touch sensor.

mytouchsensor = touchSensor(myev3)
mytouchsensor = 

  touchSensor with properties:

    InputPort: 1

Read the state of the touch sensor.

pressed = readTouch(mytouchsensor)
pressed =

     0

This result indicates that an object is not pressing the touch sensor.

Press the touch sensor while you take another reading.

pressed = readTouch(mytouchsensor)
pressed =

     1

This result indicates that an object is pressing the touch sensor.

Input Arguments

collapse all

Connection to touch sensor, specified as a string that represents the object created using touchSensor.

Example: mytouchsensor

Data Types: char

Output Arguments

collapse all

Touch sensor status, returned as a logical value:

  • 0 means not pressed.

  • 1 means pressed.