def get_sensor_avg(self, samples, softstart=100):
'''Return the average readings from the sensors over the
given number of samples. Discard the first softstart
samples to give things time to settle.'''
sample = self.read_sensors()
counters = [0] * 7
for i in range(samples + softstart):
# the sleep here is to ensure we read a new sample
# each time
time.sleep_ms(2)
sample = self.read_sensors()
if i < softstart:
continue
for j, val in enumerate(sample):
counters[j] += val
return [x//samples for x in counters]
评论列表
文章目录