Skip to content

Commit efe5557

Browse files
authored
Added get_distance() to ColourDistanceSensor (#157)
* Add get_distance() to example code * Only return first element of array in get_distance() * Use mode 1 for distance
1 parent 9443434 commit efe5557

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

buildhat/colordistance.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ def get_reflected_light(self):
115115
readings.append(self.get()[0])
116116
return int(sum(readings) / len(readings))
117117

118+
def get_distance(self):
119+
"""Return the distance
120+
121+
:return: Distance
122+
:rtype: int
123+
"""
124+
self.mode(1)
125+
distance = self.get()[0]
126+
return distance
127+
118128
def _clamp(self, val, small, large):
119129
return max(small, min(val, large))
120130

docs/buildhat/colordistance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
color = ColorDistanceSensor('C')
66

7+
print("Distance", color.get_distance())
78
print("RGBI", color.get_color_rgb())
89
print("Ambient", color.get_ambient_light())
910
print("Reflected", color.get_reflected_light())

0 commit comments

Comments
 (0)