Skip to content

Pin Module

This module help you to manage a pin


Examples:

>>> from pybox.pin import PIN
>>> led = PIN(9, 'OUTPUT')
>>> led.value = 1

The user basically should use only the PIN class inside it.

Classes

PIN

PIN class

Parameters:

  • pin (int, default: None ) –

    pin to drive

  • direction (str, default: None ) –

    INPUT or OUTPUT

Source code in pybox/pin.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class PIN:
    """PIN class

    Args:
        pin (int): pin to drive
        direction (str): `INPUT` or `OUTPUT`
    """

    def __init__(self, pin: int = None, direction: str = None):
        n_pin = getattr(board, f'GP{pin}')
        self._pin = digitalio.DigitalInOut(n_pin)

        if direction in ['INPUT', 'OUTPUT']:
            _dir = getattr(digitalio.Direction, direction)
            self._pin.direction = _dir
        else:
            raise ValueError(
                "Please choose one of the following options: 'INPUT','OUTPUT'")

        self._value = 0

    @property
    def value(self):
        """Get or set pin value

        Returns:
            (int): 0 for null voltage (GND), 1 for maximum voltage (3V3)
        """
        return 1 if self._pin.value else 0

    @value.setter
    def value(self, val: int = 0):
        self._pin.value = bool(val)

Attributes

value property writable

Get or set pin value

Returns:

  • int

    0 for null voltage (GND), 1 for maximum voltage (3V3)