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

Method __init__

Software/Python/easysensors.py:392–429  ·  view source on GitHub ↗

Binds an analog device to the specified ``port`` with the appropriate ``pinmode`` mode. :param str port: The port to which the sensor/actuator is connected. :param str pinmode: The pin mode of the device that's connected to the `GoPiGo3`_. :param easygopigo3.EasyGoP

(self, port, pinmode, gpg, use_mutex = False)

Source from the content-addressed store, hash-verified

390
391 """
392 def __init__(self, port, pinmode, gpg, use_mutex = False):
393 """
394 Binds an analog device to the specified ``port`` with the appropriate ``pinmode`` mode.
395
396 :param str port: The port to which the sensor/actuator is connected.
397 :param str pinmode: The pin mode of the device that's connected to the `GoPiGo3`_.
398 :param easygopigo3.EasyGoPiGo3 gpg: Required object for instantiating an :py:class:`~easysensors.AnalogSensor` object.
399 :param bool use_mutex = False: When using multiple threads/processes that access the same resource/device, mutexes should be enabled.
400 :raises TypeError: If the ``gpg`` parameter is not a :py:class:`~easygopigo3.EasyGoPiGo3` object.
401
402 The available ``port``'s for use are the following:
403
404 * ``"AD1"`` - general purpose input/output port.
405 * ``"AD2"`` - general purpose input/output port.
406
407 The ports' locations can be seen in the following graphical representation: :ref:`hardware-ports-section`.
408
409 .. important::
410
411 Since the grove connector allows 2 signals to pass through 2 pins (not concurently), we can select which pin to go with by using the :py:meth:`~easysensors.Sensor.set_pin` method.
412 By default, we're using pin **1**, which corresponds to the exterior pin of the grove connector (aka SIG) and the wire is yellow.
413
414 """
415 debug("AnalogSensor init")
416
417 self.value = 0
418 self.freq = 24000
419 self._max_value = 4096
420 try:
421 Sensor.__init__(self, port, pinmode, gpg, use_mutex)
422 except:
423 raise("AnalogSensor Init")
424
425 # select the outwards pin of the grove connector
426 self.set_pin(1)
427
428 # this delay is at least needed by the Light sensor
429 time.sleep(0.01)
430
431 def read(self):
432 """

Callers

nothing calls this directly

Calls 3

set_pinMethod · 0.80
debugFunction · 0.70
__init__Method · 0.45

Tested by

no test coverage detected