Class NXTUltrasonicSensor

    • Constructor Detail

      • NXTUltrasonicSensor

        public NXTUltrasonicSensor​(I2CPort port)
      • NXTUltrasonicSensor

        public NXTUltrasonicSensor​(Port port)
    • Method Detail

      • getData

        public void getData​(int register,
                            byte[] buf,
                            int off,
                            int len)
        Description copied from class: I2CSensor
        Executes an I2C read transaction and waits for the result.
        Overrides:
        getData in class I2CSensor
        Parameters:
        register - I2C register, e.g 0x41
        buf - Buffer to return data
        off - Offset of the start of the data
        len - Length of the return data
      • sendData

        public void sendData​(int register,
                             byte[] buf,
                             int off,
                             int len)
        Description copied from class: I2CSensor
        Executes an I2C write transaction.
        Overrides:
        sendData in class I2CSensor
        Parameters:
        register - I2C register, e.g 0x42
        buf - Buffer containing data to send
        off - Offset of the start of the data
        len - Length of data to send
      • getDistanceMode

        public SampleProvider getDistanceMode()
        Gives a SampleProvider representing the sensor in distance mode. In this mode the sensor scans the surrounding continuously and reports the distance to the nearest object in sight. The sensor reports the distance to the nearest object in meters. The theoretical range of the sensor is 0,04 to 2.54 meter. If there is no object detected within this range the sensor reports Float.POSITIVE_INFINITY.
        Samples can only be provided every 30 ms. If samples are fetched more often the SampleProvider will pause until the 30ms have passed.
        Returns:
        A SamplePrivider
      • getPingMode

        public SampleProvider getPingMode()
        Gives a SampleProvider representing the sensor in ping mode. In this mode the sensor only scans the surrounding upon request, ie by calling fetchSample method. The sensor reports the distance, expressed in meters, to the eight nearest objects in sight. The theoretical range of the sensor is 0,04 to 2.54 meter. If there are less then eight objects within the sensors range the sensor will reports Float.POSITIVE_INFINITY. Fetching a sample in ping mode takes about 70 ms.
        Returns:
        the sample provider
      • enable

        public void enable()
      • disable

        public void disable()
      • isEnabled

        public boolean isEnabled()
      • setMode

        protected boolean setMode​(byte mode)
        Sets the sensor to CONTINUOUS, PING or OFF
        Parameters:
        mode -
        Returns:
        True, if the mode was changed.
        False, if the mode was already in the requested state.