platypush/plugins/pwm/pca9685/__init__.py
def write(self, value: Optional[int] = None, channels: Optional[Dict[int, float]] = None,
              frequency: Optional[float] = None, step: Optional[int] = None,
              step_duration: Optional[float] = None):
        """
        Send PWM values to the channels.

        :param value: Send the value to all the channels (or to all the configured default channels).
            ``value`` and ``channels`` are mutually exclusive.
        :param channels: Map of the values to be written, as a ``channel_index -> value``, where value is a real number.
            ``value`` and ``channels`` are mutually exclusive.
        :param frequency: Override default frequency.
        :param step: If set, then the PWM duty cycle will be increased/decreased by
            this much per cycle (i.e. 1/frequency). This is useful when dealing with PWM
            devices that require smooth transitions, arming sequences or ramping signals.
            If None (default) then the new PWM values will be directly written with no
            ramping logic.
        :param step_duration: If step is configured, this parameter identifies how long
            each step should last (default: ``1/frequency``).
        """
        import busio
        from board import SCL, SDA
        from adafruit_pca9685 import PCA9685

        if value is not None:
            assert self.channels, 'No default channels configured'
            channels = {i: value for i in self.channels}

        assert channels, 'Both value and channels are missing'

        i2c_bus = busio.I2C(SCL, SDA)
        pca = self._pca = self._pca or PCA9685(i2c_bus)
        pca.frequency = frequency or self.frequency
        step_duration = step_duration or 1/pca.frequency

        if not step:
            for i, val in channels.items():
                pca.channels[i].duty_cycle = val
            return

        done = False
        cur_values = {
            i: channel.duty_cycle
            for i, channel in enumerate(pca.channels)
        }

        while not done:
            done = True

            for i, val in channels.items():
                if val == cur_values[i]:
                    continue

                done = False
                val = min(cur_values[i] + step, val, self.max_duty_cycle) \
                        if val > pca.channels[i].duty_cycle \
                        else max(cur_values[i] - step, val, self.min_duty_cycle)

                pca.channels[i].duty_cycle = cur_values[i] = val

            time.sleep(step_duration)

        Send PWM values to the channels.

        :param value: Send the value to all the channels (or to all the configured default channels).
            ``value`` and ``channels`` are mutually exclusive.
        :param channels: Map of the values to be written, as a ``channel_index -> value``, where value is a real number.
            ``value`` and ``channels`` are mutually exclusive.
        :param frequency: Override default frequency.
        :param step: If set, then the PWM duty cycle will be increased/decreased by
            this much per cycle (i.e. 1/frequency). This is useful when dealing with PWM
            devices that require smooth transitions, arming sequences or ramping signals.
            If None (default) then the new PWM values will be directly written with no
            ramping logic.
        :param step_duration: If step is configured, this parameter identifies how long
            each step should last (default: ``1/frequency``).
        
Send PWM values to the channels.
Send PWM values to the channels .
def write(self, value: Optional[int] = None, channels: Optional[Dict[int, float]] = None,
              frequency: Optional[float] = None, step: Optional[int] = None,
              step_duration: Optional[float] = None):
        import busio
        from board import SCL, SDA
        from adafruit_pca9685 import PCA9685
        if value is not None:
            assert self.channels, 'No default channels configured'
            channels = {i: value for i in self.channels}
        assert channels, 'Both value and channels are missing'
        i2c_bus = busio.I2C(SCL, SDA)
        pca = self._pca = self._pca or PCA9685(i2c_bus)
        pca.frequency = frequency or self.frequency
        step_duration = step_duration or 1/pca.frequency
        if not step:
            for i, val in channels.items():
                pca.channels[i].duty_cycle = val
            return
        done = False
        cur_values = {
            i: channel.duty_cycle
            for i, channel in enumerate(pca.channels)
        }
        while not done:
            done = True
            for i, val in channels.items():
                if val == cur_values[i]:
                    continue
                done = False
                val = min(cur_values[i] + step, val, self.max_duty_cycle) \
                        if val > pca.channels[i].duty_cycle \
                        else max(cur_values[i] - step, val, self.min_duty_cycle)
                pca.channels[i].duty_cycle = cur_values[i] = val
            time.sleep(step_duration)
def write ( self , value : Optional [ int ] = None , channels : Optional [ Dict [ int , float ] ] = None , frequency : Optional [ float ] = None , step : Optional [ int ] = None , step_duration : Optional [ float ] = None ) : import busio from board import SCL , SDA from adafruit_pca9685 import PCA9685 if value is not None : assert self . channels , 'No default channels configured' channels = { i : value for i in self . channels } assert channels , 'Both value and channels are missing' i2c_bus = busio . I2C ( SCL , SDA ) pca = self . _pca = self . _pca or PCA9685 ( i2c_bus ) pca . frequency = frequency or self . frequency step_duration = step_duration or 1 / pca . frequency if not step : for i , val in channels . items ( ) : pca . channels [ i ] . duty_cycle = val return done = False cur_values = { i : channel . duty_cycle for i , channel in enumerate ( pca . channels ) } while not done : done = True for i , val in channels . items ( ) : if val == cur_values [ i ] : continue done = False val = min ( cur_values [ i ] + step , val , self . max_duty_cycle ) if val > pca . channels [ i ] . duty_cycle else max ( cur_values [ i ] - step , val , self . min_duty_cycle ) pca . channels [ i ] . duty_cycle = cur_values [ i ] = val time . sleep ( step_duration )
Send PWM values to the channels.
Send PWM values to the channels .
"""
        Send PWM values to the channels.

        :param value: Send the value to all the channels (or to all the configured default channels).
            ``value`` and ``channels`` are mutually exclusive.
        :param channels: Map of the values to be written, as a ``channel_index -> value``, where value is a real number.
            ``value`` and ``channels`` are mutually exclusive.
        :param frequency: Override default frequency.
        :param step: If set, then the PWM duty cycle will be increased/decreased by
            this much per cycle (i.e. 1/frequency). This is useful when dealing with PWM
            devices that require smooth transitions, arming sequences or ramping signals.
            If None (default) then the new PWM values will be directly written with no
            ramping logic.
        :param step_duration: If step is configured, this parameter identifies how long
            each step should last (default: ``1/frequency``).
        """
self
value
Optional[int]
Send the value to all the channels (or to all the configured default channels).
``value`` and ``channels`` are mutually exclusive.
Send the value to all the channels ( or to all the configured default channels ) . ` ` value ` ` and ` ` channels ` ` are mutually exclusive .
channels
Optional[Dict[int, float]]
Map of the values to be written, as a ``channel_index -> value``, where value is a real number.
``value`` and ``channels`` are mutually exclusive.
Map of the values to be written as a ` ` channel_index - > value ` ` where value is a real number . ` ` value ` ` and ` ` channels ` ` are mutually exclusive .
frequency
Optional[float]
Override default frequency.
Override default frequency .
step
Optional[int]
If set, then the PWM duty cycle will be increased/decreased by
this much per cycle . This is useful when dealing with PWM
devices that require smooth transitions, arming sequences or ramping signals.
If None (default) then the new PWM values will be directly written with no
ramping logic.
If set then the PWM duty cycle will be increased / decreased by this much per cycle . This is useful when dealing with PWM devices that require smooth transitions arming sequences or ramping signals . If None ( default ) then the new PWM values will be directly written with no ramping logic .
step_duration
Optional[float]
If step is configured, this parameter identifies how long
each step should last (default: ``1/frequency``).
If step is configured this parameter identifies how long each step should last ( default : ` ` 1 / frequency ` ` ) .