We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 11b4dd5 + 4c44f1c commit 33b31dfCopy full SHA for 33b31df
buildhat/colordistance.py
@@ -102,10 +102,15 @@ def get_reflected_light(self):
102
readings.append(self.get()[0])
103
return int(sum(readings)/len(readings))
104
105
+ def _clamp(self, val, small, large):
106
+ return max(small, min(val, large))
107
+
108
def _avgrgb(self, reads):
109
readings = []
110
for read in reads:
- read = [int((read[0]/1024)*255), int((read[1]/1024)*255), int((read[2]/1024)*255)]
111
+ read = [int((self._clamp(read[0], 0, 400)/400)*255),
112
+ int((self._clamp(read[1], 0, 400)/400)*255),
113
+ int((self._clamp(read[2], 0, 400)/400)*255)]
114
readings.append(read)
115
rgb = []
116
for i in range(3):
@@ -157,7 +162,7 @@ def wait_for_new_color(self):
157
162
def cb(lst):
158
163
data.append(lst)
159
164
if len(data) == self.avg_reads:
160
- r, g, b, _ = self._avgrgb(data)
165
+ r, g, b = self._avgrgb(data)
161
166
seg = self.segment_color(r, g, b)
167
if seg != self._old_color:
168
self._old_color = seg
0 commit comments