Exemplo n.º 1
0
    def distance_centimeters_continuous(self):
        """
        Measurement of the distance detected by the sensor,
        in centimeters.

        The sensor will continue to take measurements so
        they are available for future reads.

        Prefer using the equivalent :meth:`UltrasonicSensor.distance_centimeters` property.
        """

        self._ensure_mode(self.MODE_US_DIST_CM)

        value = self.connector.get_value()
        return value if value == -1 else value * get_cm_multiplier()
Exemplo n.º 2
0
    def distance_centimeters_ping(self):
        """
        Measurement of the distance detected by the sensor,
        in centimeters.

        The sensor will take a single measurement then stop
        broadcasting.

        If you use this property too frequently (e.g. every
        100msec), the sensor will sometimes lock up and writing
        to the mode attribute will return an error. A delay of
        250msec between each usage seems sufficient to keep the
        sensor from locking up.
        """

        # This mode is special; setting the mode causes the sensor to send out
        # a "ping", but the mode isn't actually changed.

        self.mode = self.MODE_US_SI_CM

        value = self.connector.get_value()
        return value if value == -1 else value * get_cm_multiplier()