Skip to content

Commit 7364172

Browse files
authored
Merge pull request #37 from CedarGroveStudios/pwm-freq-get-set
Add PWM frequency getter/setter and init keyword argument
2 parents 010c65e + d964388 commit 7364172

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

adafruit_motorkit.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
5252
"""
5353

54-
5554
import board
5655
from adafruit_pca9685 import PCA9685
5756

@@ -67,7 +66,9 @@ class MotorKit:
6766
6867
Alternately, if using with multiple I2C devices, you can specify the I2C bus."""
6968

70-
def __init__(self, address=0x60, i2c=None, steppers_microsteps=16):
69+
def __init__(
70+
self, address=0x60, i2c=None, steppers_microsteps=16, pwm_frequency=1600
71+
):
7172
self._motor1 = None
7273
self._motor2 = None
7374
self._motor3 = None
@@ -77,7 +78,7 @@ def __init__(self, address=0x60, i2c=None, steppers_microsteps=16):
7778
if i2c is None:
7879
i2c = board.I2C()
7980
self._pca = PCA9685(i2c, address=address)
80-
self._pca.frequency = 1600
81+
self._pca.frequency = pwm_frequency
8182
self._steppers_microsteps = steppers_microsteps
8283

8384
# We can save memory usage (~300 bytes) by deduplicating the construction of the objects for
@@ -296,3 +297,12 @@ def stepper2(self):
296297
microsteps=self._steppers_microsteps,
297298
)
298299
return self._stepper2
300+
301+
@property
302+
def frequency(self):
303+
"""The overall PCA9685 PWM frequency in Hertz."""
304+
return self._pca.frequency
305+
306+
@frequency.setter
307+
def frequency(self, pwm_frequency=1600):
308+
self._pca.frequency = pwm_frequency

0 commit comments

Comments
 (0)