How to use the gpiozero.output_devices.OutputDevice function in gpiozero

To help you get started, we’ve selected a few gpiozero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gpiozero / gpiozero / gpiozero / output_devices.py View on Github external
def value(self):
        """
        Returns 1 if the device is currently active and 0 otherwise. Setting
        this property changes the state of the device.
        """
        return super(OutputDevice, self).value
github gpiozero / gpiozero / gpiozero / output_devices.py View on Github external
If :data:`False` (the default), the buzzer will be silent initially. If
        :data:`None`, the buzzer will be left in whatever state the pin is
        found in when configured for output (warning: this can be on). If
        :data:`True`, the buzzer will be switched on initially.

    :type pin_factory: Factory or None
    :param pin_factory:
        See :doc:`api_pins` for more information (this is an advanced feature
        which most users can ignore).
    """
    pass

Buzzer.beep = Buzzer.blink


class PWMOutputDevice(OutputDevice):
    """
    Generic output device configured for pulse-width modulation (PWM).

    :type pin: int or str
    :param pin:
        The GPIO pin that the device is connected to. See :ref:`pin-numbering`
        for valid pin numbers. If this is :data:`None` a :exc:`GPIODeviceError`
        will be raised.

    :param bool active_high:
        If :data:`True` (the default), the :meth:`on` method will set the GPIO
        to HIGH. If :data:`False`, the :meth:`on` method will set the GPIO to
        LOW (the :meth:`off` method always does the opposite).

    :param float initial_value:
        If 0 (the default), the device's duty cycle will be 0 initially.
github gpiozero / gpiozero / gpiozero / pins / spi.py View on Github external
def __init__(self, clock_pin, mosi_pin, miso_pin):
        self.lock = None
        self.clock = None
        self.mosi = None
        self.miso = None
        super(SPISoftwareBus, self).__init__()
        self.lock = RLock()
        try:
            self.clock = OutputDevice(clock_pin, active_high=True)
            if mosi_pin is not None:
                self.mosi = OutputDevice(mosi_pin)
            if miso_pin is not None:
                self.miso = InputDevice(miso_pin)
        except:
            self.close()
            raise
github gpiozero / gpiozero / gpiozero / spi.py View on Github external
def __init__(self, clock_pin, mosi_pin, miso_pin):
        self.lock = None
        self.clock = None
        self.mosi = None
        self.miso = None
        super(SPISoftwareBus, self).__init__()
        self.lock = RLock()
        try:
            self.clock = OutputDevice(clock_pin, active_high=True)
            if mosi_pin is not None:
                self.mosi = OutputDevice(mosi_pin)
            if miso_pin is not None:
                self.miso = InputDevice(miso_pin)
        except:
            self.close()
            raise
github gpiozero / gpiozero / gpiozero / boards.py View on Github external
def __init__(self, pin_factory=None):
        self._lock = Lock()
        super(_EnergenieMaster, self).__init__(
            *(
                OutputDevice(pin, pin_factory=pin_factory)
                for pin in (17, 22, 23, 27)
            ),
            mode=OutputDevice(24, pin_factory=pin_factory),
            enable=OutputDevice(25, pin_factory=pin_factory),
            _order=('mode', 'enable'), pin_factory=pin_factory
        )
github gpiozero / gpiozero / gpiozero / boards.py View on Github external
def __init__(self, pin_factory=None):
        self._lock = Lock()
        super(_EnergenieMaster, self).__init__(
            *(
                OutputDevice(pin, pin_factory=pin_factory)
                for pin in (17, 22, 23, 27)
            ),
            mode=OutputDevice(24, pin_factory=pin_factory),
            enable=OutputDevice(25, pin_factory=pin_factory),
            _order=('mode', 'enable'), pin_factory=pin_factory
        )
github gpiozero / gpiozero / gpiozero / pins / spi.py View on Github external
def __init__(self, clock_pin, mosi_pin, miso_pin):
        self.lock = None
        self.clock = None
        self.mosi = None
        self.miso = None
        super(SPISoftwareBus, self).__init__()
        self.lock = RLock()
        try:
            self.clock = OutputDevice(clock_pin, active_high=True)
            if mosi_pin is not None:
                self.mosi = OutputDevice(mosi_pin)
            if miso_pin is not None:
                self.miso = InputDevice(miso_pin)
        except:
            self.close()
            raise
github gpiozero / gpiozero / gpiozero / spi.py View on Github external
if self.mosi is not None:
                        self.mosi.value = bool(write_word & mask)
                    self.clock.on()
                    if self.miso is not None and not clock_phase:
                        if self.miso.value:
                            read_word |= mask
                    self.clock.off()
                    if self.miso is not None and clock_phase:
                        if self.miso.value:
                            read_word |= mask
                    mask = shift(mask, 1)
                result.append(read_word)
        return result


class SPISoftwareInterface(OutputDevice):
    def __init__(self, clock_pin, mosi_pin, miso_pin, select_pin):
        self._bus = None
        super(SPISoftwareInterface, self).__init__(select_pin, active_high=False)
        try:
            self._clock_phase = False
            self._lsb_first = False
            self._bits_per_word = 8
            self._bus = SPISoftwareBus(clock_pin, mosi_pin, miso_pin)
        except:
            self.close()
            raise

    def close(self):
        if self._bus:
            self._bus.close()
            self._bus = None
github gpiozero / gpiozero / gpiozero / pins / local.py View on Github external
self._interface.lsbfirst = bool(value)

    def _get_select_high(self):
        return self._interface.cshigh

    def _set_select_high(self, value):
        self._interface.cshigh = bool(value)

    def _get_bits_per_word(self):
        return self._interface.bits_per_word

    def _set_bits_per_word(self, value):
        self._interface.bits_per_word = value


class LocalPiSoftwareSPI(SPI, OutputDevice):
    def __init__(self, factory, clock_pin, mosi_pin, miso_pin, select_pin):
        self._bus = None
        super(LocalPiSoftwareSPI, self).__init__(select_pin, active_high=False)
        try:
            self._clock_phase = False
            self._lsb_first = False
            self._bits_per_word = 8
            self._bus = SPISoftwareBus(clock_pin, mosi_pin, miso_pin)
        except:
            self.close()
            raise

    def _conflicts_with(self, other):
        # XXX Need to refine this
        return not (
            isinstance(other, LocalPiSoftwareSPI) and
github gpiozero / gpiozero / gpiozero / boards.py View on Github external
def __init__(self, pin_factory=None):
        self._lock = Lock()
        super(_EnergenieMaster, self).__init__(
            *(
                OutputDevice(pin, pin_factory=pin_factory)
                for pin in (17, 22, 23, 27)
            ),
            mode=OutputDevice(24, pin_factory=pin_factory),
            enable=OutputDevice(25, pin_factory=pin_factory),
            _order=('mode', 'enable'), pin_factory=pin_factory
        )