MCPcopy Create free account
hub / github.com/DexterInd/GoPiGo3 / percent_read

Method percent_read

Software/Python/easysensors.py:454–469  ·  view source on GitHub ↗

Reads analog value of the sensor that's connected to our `GoPiGo3`_ robot as a percentage. :returns: Percentage mapped to 0V-5V range. :rtype: int

(self)

Source from the content-addressed store, hash-verified

452 return self.value
453
454 def percent_read(self):
455 """
456 Reads analog value of the sensor that's connected to our `GoPiGo3`_ robot as a percentage.
457
458 :returns: Percentage mapped to 0V-5V range.
459 :rtype: int
460
461 """
462 reading_percent = round(self.read() * 100 // self._max_value)
463
464 # Some sensors - like the loudness_sensor -
465 # can actually return higher than 100% so let's clip it
466 # and keep classrooms within an acceptable noise level
467 if reading_percent > 100:
468 reading_percent = 100
469 return reading_percent
470
471 def write(self, power):
472 """

Callers 3

handle_lightFunction · 0.80
handle_loudnessFunction · 0.80

Calls 1

readMethod · 0.95

Tested by

no test coverage detected