class devices.Touch(ev3handle, layer=1, portnum=1, inputmode='touch')[source]

The class to represent the EV3 touch sensor.

Set up a touch sensor on port number 1

>>> from pyev3.brick import LegoEV3
>>> from pyev3.devices import Touch
>>> myev3 = LegoEV3(commtype='usb')
>>> mysensor = Touch(myev3, portnum=1, inputmode='bump')
  • ev3handle (object) – LegoEV3 instance representing the EV3 brick.

  • layer (int) – The layer of the brick 1 or 2 in a daisy-chain configuration.

  • portnum (int) – The brick input port connected to the sensor. Possible values are 1, 2, 3, or 4.

  • inputmode (str) –

    • 'touch' to check the button state (pressed or released)

    • 'bump' to count the number of press/release events


Displays a summary with the sensor information.


Reset the touch sensor event counter.

>>> mysensor.reset_count()
property inputmode

Contains the sensor input mode. Use this to change the mode on the fly (read/write).

property output

Contains the sensor output based on the inputmode (read only).

  • 1 or 0 (inputmode=’touch’)

  • int (inputmode=’bump’)