brian.sensors.NXT.TouchSensorNXT
TouchSensorNXT class objects
Class for interacting with NXT 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 TouchSensorNXT.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__
Initialize an NXT touch sensor at the given port.
Arguments:
port
: Sensor port to which the sensor is attached.
is_pressed
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
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.
Raises:
brian.sensors.SensorIsNotReadyError
: If the sensor is not ready.
Returns:
success
: - True: If the desired button event was caught.
- False: If the timeout ran out.
wait_for_release
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.
Raises:
brian.sensors.SensorIsNotReadyError
: If the sensor is not ready.
Returns:
success
: - True: If the desired button event was caught.
- False: If the timeout ran out.
wait_for_press_and_release
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.
Raises:
brian.sensors.SensorIsNotReadyError
: If the sensor is not ready.
Returns:
success
: - True: If the desired button event was caught.
- False: If the timeout ran out.