Skip to content

brian.sensors.EV3.TouchSensorEV3

brian.sensors.EV3

TouchSensorEV3 class objects

class TouchSensorEV3(Sensor)

Class for interacting with EV3 touch sensor.

Sensor is automatically registered in the constructor of the base class and un-registered in its destructor. It can also be unregistered with the TouchSensorEV3.close_sensor() function.

There can be at most one instance at any given time, of any sensor class per port in the entire program.

__init__

def __init__(port: SensorPort)

Initialize a EV3 touch sensor at the given port.

Arguments:

  • port: Sensor port to which the sensor is attached.

is_pressed

def is_pressed() -> bool

Measures the sensor state. Returns boolean of the last button pressed state.

If the sensor is not ready, returns False.

Raises:

  • brian.sensors.SensorIsNotReadyError: If the sensor is not ready.

Returns:

True if the sensor button is pressed, False otherwise. Or False if the sensor is not ready.

wait_for_press

def wait_for_press(timeout_ms: int = -1) -> bool

Waits for next button press event.

This function is blocking.

Arguments:

  • timeout_ms: Maximum number of milliseconds to wait. If the timeout is negative, the function will wait indefinitely.

Returns:

success: - True: If the desired button event was caught. - False: If the timeout ran out.

wait_for_release

def wait_for_release(timeout_ms: int = -1) -> bool

Waits for next button release event.

This function is blocking.

Arguments:

  • timeout_ms: Maximum number of milliseconds to wait. If the timeout is negative, the function will wait indefinitely.

Returns:

success: - True: If the desired button event was caught. - False: If the timeout ran out.

wait_for_press_and_release

def wait_for_press_and_release(timeout_ms: int = -1) -> bool

Waits for next button press and release event.

This function is blocking.

Arguments:

  • timeout_ms: Maximum number of milliseconds to wait. If the timeout is negative, the function will wait indefinitely.

Returns:

success: - True: If the desired button event was caught. - False: If the timeout ran out.