Skip to content

Commit 18eb504

Browse files
Merge pull request #34 from kriswilk/patch-1
Add functionality to set the Real-Time Playback value
2 parents 2200f21 + f4c324d commit 18eb504

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

adafruit_drv2605.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,44 @@ def sequence(self) -> "_DRV2605_Sequence":
208208
"""
209209
return self._sequence
210210

211+
@property
212+
def realtime_value(self) -> int:
213+
"""The output value used in Real-Time Playback mode. When the device is
214+
switched to ``MODE_REALTIME``, the motor is driven continuously with an
215+
amplitude/direction determined by this value.
216+
217+
By default, the device expects a SIGNED 8-bit integer, and its exact
218+
effect depends on both the type of motor (ERM/LRA) and whether the device
219+
is operating in open- or closed-loop (unidirectional/bidirectional) mode.
220+
221+
See the datasheet for more information!
222+
223+
E.g.:
224+
225+
.. code-block:: python
226+
227+
# Start real-time playback
228+
drv.realtime_value = 0
229+
drv.mode = adafruit_drv2605.MODE_REALTIME
230+
231+
# Buzz the motor briefly at 50% and 100% amplitude
232+
drv.realtime_value = 64
233+
time.sleep(0.5)
234+
drv.realtime_value = 127
235+
time.sleep(0.5)
236+
237+
# Stop real-time playback
238+
drv.realtime_value = 0
239+
drv.mode = adafruit_drv2605.MODE_INTTRIG
240+
"""
241+
return self._read_u8(_DRV2605_REG_RTPIN)
242+
243+
@realtime_value.setter
244+
def realtime_value(self, val: int) -> None:
245+
if not -127 <= val <= 255:
246+
raise ValueError("Real-Time Playback value must be between -127 and 255!")
247+
self._write_u8(_DRV2605_REG_RTPIN, val)
248+
211249
def set_waveform(self, effect_id: int, slot: int = 0) -> None:
212250
"""Select an effect waveform for the specified slot (default is slot 0,
213251
but up to 8 effects can be combined with slot values 0 to 7). See the

0 commit comments

Comments
 (0)