Skip to content

Commit 4e51c8f

Browse files
authored
Adjust permitted input for realtime_value, improve docstring and example
1 parent ab70daa commit 4e51c8f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

adafruit_drv2605.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,29 +214,36 @@ def realtime_value(self) -> int:
214214
switched to ``MODE_REALTIME``, the motor is driven continuously with an
215215
amplitude/direction determined by this value.
216216
217-
By default, the device interprets it as SIGNED (2s complement), and its exact
218-
effect depends on other operating parameters.
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.
219220
220221
See the datasheet for more information!
221222
222223
E.g.:
223224
224225
.. code-block:: python
225226
226-
# Configure the output amplitude to 50%
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
227232
drv.realtime_value = 64
233+
time.sleep(0.5)
234+
drv.realtime_value = 127
235+
time.sleep(0.5)
228236
229-
# Buzz the motor briefly
230-
drv.mode = adafruit_drv2605.MODE_REALTIME
231-
time.sleep(0.25)
237+
# Stop real-time playback
238+
drv.realtime_value = 0
232239
drv.mode = adafruit_drv2605.MODE_INTTRIG
233240
"""
234241
return self._read_u8(_DRV2605_REG_RTPIN)
235242

236243
@realtime_value.setter
237244
def realtime_value(self, val: int) -> None:
238-
if not 0 <= val <= 255:
239-
raise ValueError("Real-Time Playback value must be a value within 0-255!")
245+
if not -127 <= val <= 255:
246+
raise ValueError("Real-Time Playback value must be a value between -127 and 255!")
240247
self._write_u8(_DRV2605_REG_RTPIN, val)
241248

242249
def set_waveform(self, effect_id: int, slot: int = 0) -> None:

0 commit comments

Comments
 (0)