Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions buildhat/colordistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
1 change: 1 addition & 0 deletions docs/buildhat/colordistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down