From 19e4d3d36f245b54d44cfe3251fa3ea6a151c6df Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Tue, 14 Jan 2020 20:12:27 +0100 Subject: [PATCH] api/nxtdevices: add Touch Sensor --- doc/api/nxtdevices.rst | 22 ++++++++++++++++++++++ pybricks/nxtdevices.py | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/doc/api/nxtdevices.rst b/doc/api/nxtdevices.rst index 92894e9..b6eabaf 100644 --- a/doc/api/nxtdevices.rst +++ b/doc/api/nxtdevices.rst @@ -8,3 +8,25 @@ NXT Motor ^^^^^^^^^^^^^^^^ This motor works just like a LEGO MINDSTORMS EV3 Large Motor. You can use it in your programs using the :mod:`Motor <.ev3devices>` class. + +NXT Touch Sensor +^^^^^^^^^^^^^^^^ +.. autoclass:: pybricks.nxtdevices.TouchSensor + :no-members: + + .. automethod:: pybricks.nxtdevices.TouchSensor.pressed + + .. toggle-header:: + :header: **Using older NXT Touch Sensors** + + **Example: Using a first-generation NXT Touch Sensor.** + + Normally, the EV3 brick always verifies that a sensor is attached + before you can use it. This means that your program stops if a sensor + that you selected was not found. The very first generation of NXT Touch + Sensors did not support this functionality. + To use these sensors, set ``verify_type=False`` as follows:: + + from pybricks.nxtdevices import TouchSensor + from pybricks.parameters import Port + my_sensor = TouchSensor(Port.S1, verify_type=False) diff --git a/pybricks/nxtdevices.py b/pybricks/nxtdevices.py index f468f48..e5783db 100644 --- a/pybricks/nxtdevices.py +++ b/pybricks/nxtdevices.py @@ -1,2 +1,23 @@ """Use LEGO® MINDSTORMS® NXT motors and sensors with the EV3 brick.""" + +class TouchSensor(): + """LEGO® MINDSTORMS® NXT Touch Sensor.""" + + def __init__(self, port): + """ + + Arguments: + port (Port): Port to which the sensor is connected. + """ + pass + + def pressed(self): + """Check if the sensor is pressed. + + Returns: + bool: ``True`` if the sensor is pressed, ``False`` if it is + not pressed. + + """ + pass