diff --git a/buildhat/colordistance.py b/buildhat/colordistance.py index 90f0f94..da85c3a 100644 --- a/buildhat/colordistance.py +++ b/buildhat/colordistance.py @@ -115,6 +115,16 @@ def get_reflected_light(self): readings.append(self.get()[0]) return int(sum(readings) / len(readings)) + def get_distance(self): + """Return the distance + + :return: Distance + :rtype: int + """ + self.mode(1) + distance = self.get()[0] + return distance + def _clamp(self, val, small, large): return max(small, min(val, large)) diff --git a/docs/buildhat/colordistance.py b/docs/buildhat/colordistance.py index 8a73964..d8a3466 100755 --- a/docs/buildhat/colordistance.py +++ b/docs/buildhat/colordistance.py @@ -4,6 +4,7 @@ color = ColorDistanceSensor('C') +print("Distance", color.get_distance()) print("RGBI", color.get_color_rgb()) print("Ambient", color.get_ambient_light()) print("Reflected", color.get_reflected_light())