Skip to content

Add PWM frequency getter/setter and init keyword argument #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions adafruit_motorkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

"""


import board
from adafruit_pca9685 import PCA9685

Expand All @@ -67,7 +66,9 @@ class MotorKit:

Alternately, if using with multiple I2C devices, you can specify the I2C bus."""

def __init__(self, address=0x60, i2c=None, steppers_microsteps=16):
def __init__(
self, address=0x60, i2c=None, steppers_microsteps=16, pwm_frequency=1600
):
self._motor1 = None
self._motor2 = None
self._motor3 = None
Expand All @@ -77,7 +78,7 @@ def __init__(self, address=0x60, i2c=None, steppers_microsteps=16):
if i2c is None:
i2c = board.I2C()
self._pca = PCA9685(i2c, address=address)
self._pca.frequency = 1600
self._pca.frequency = pwm_frequency
self._steppers_microsteps = steppers_microsteps

# We can save memory usage (~300 bytes) by deduplicating the construction of the objects for
Expand Down Expand Up @@ -296,3 +297,12 @@ def stepper2(self):
microsteps=self._steppers_microsteps,
)
return self._stepper2

@property
def frequency(self):
"""The overall PCA9685 PWM frequency in Hertz."""
return self._pca.frequency

@frequency.setter
def frequency(self, pwm_frequency=1600):
self._pca.frequency = pwm_frequency