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

Method read

Software/Python/easysensors.py:431–452  ·  view source on GitHub ↗

Reads analog value of the sensor that's connected to our `GoPiGo3`_ robot. :returns: 12-bit number representing the voltage we get from the sensor. Range goes from 0V-5V. :rtype: int :raises gopigo3.ValueError: If an invalid value was read. :raises Exception

(self)

Source from the content-addressed store, hash-verified

429 time.sleep(0.01)
430
431 def read(self):
432 """
433 Reads analog value of the sensor that's connected to our `GoPiGo3`_ robot.
434
435 :returns: 12-bit number representing the voltage we get from the sensor. Range goes from 0V-5V.
436 :rtype: int
437 :raises gopigo3.ValueError: If an invalid value was read.
438 :raises Exception: If any other errors happens.
439
440 """
441 try:
442 self.value = self.gpg.get_grove_analog(self.get_pin())
443 except gopigo3.ValueError as e:
444 try:
445 self.value = self.gpg.get_grove_analog(self.get_pin())
446 except Exception as e:
447 print("Value Error: {}".format(e))
448 return 0
449 except Exception as e:
450 print("Analog Read fail-all: {}".format(e))
451 # print("Analog Read: {}".format(self.value))
452 return self.value
453
454 def percent_read(self):
455 """

Callers 1

percent_readMethod · 0.95

Calls 2

get_pinMethod · 0.80
get_grove_analogMethod · 0.45

Tested by

no test coverage detected