Main Content

Touch Sensor

Detect status of EV3 brick touch sensor

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

  • Touch Sensor block

Libraries:
Simulink Support Package for LEGO MINDSTORMS EV3 Hardware

Description

Use the Touch Sensor block to detect whether the touch sensor connected to the LEGO® MINDSTORMS® EV3 brick is pressed or not.

During simulations without hardware, this block emits zeros. See Block Produces Zeros or Does Nothing in Simulation.

Examples

expand all

This example shows how to read the status of the touch sensor connected to the EV3 brick on a display.

Open the legoev3lib block library and copy the Touch Sensor block as described in Open Block Library for LEGO MINDSTORMS EV3 Hardware.

Open the legoev3lib block library and copy the Display block to the same model and connect the blocks.

Connect the touch sensor to port 1 of the EV3 brick.

NXT Touch Sensor model

Prepare and run the model on the EV3 brick as described in Run Model on EV3 Hardware. Observe the state of the touch sensor on the LCD display of the EV3 brick while you press and release the touch sensor.

Ports

Output

expand all

The block outputs the status of the LEGO MINDSTORMS EV3 brick touch sensor.

  • 0 — Indicates that the touch sensor is not pressed.

  • 1 — Indicates that the touch sensor is pressed.

Data Types: uint8

Parameters

expand all

Select the EV3 brick input port to which the touch sensor is connected. Avoid assigning multiple devices to the same input port.

Specify the frequency of how often the block reads the touch sensor status. Shorter sample times, such as 0.01, may produce unreliable measurements.

Smaller sample times require the processor to complete the same number of instructions in less time, which can cause task overruns.

Version History

Introduced in R2012a