Skip to content

add PWM frequency getter/setter and init keyword arg #34

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

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 11 additions & 2 deletions adafruit_motorkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ 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 +77,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 +296,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