Simple test

Ensure your device works with this simple test.

examples/drv2605_simpletest.py
 1# SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# Simple demo of the DRV2605 haptic feedback motor driver.
 5# Will play all 123 effects in order for about a half second each.
 6import time
 7
 8import board
 9import busio
10
11import adafruit_drv2605
12
13# Initialize I2C bus and DRV2605 module.
14i2c = busio.I2C(board.SCL, board.SDA)
15drv = adafruit_drv2605.DRV2605(i2c)
16
17# Main loop runs forever trying each effect (1-123).
18# See table 11.2 in the datasheet for a list of all the effect names and IDs.
19#   http://www.ti.com/lit/ds/symlink/drv2605.pdf
20effect_id = 1
21while True:
22    print(f"Playing effect #{effect_id}")
23    drv.sequence[0] = adafruit_drv2605.Effect(effect_id)  # Set the effect on slot 0.
24    # You can assign effects to up to 8 different slots to combine
25    # them in interesting ways. Index the sequence property with a
26    # slot number 0 to 7.
27    # Optionally, you can assign a pause to a slot. E.g.
28    # drv.sequence[1] = adafruit_drv2605.Pause(0.5)  # Pause for half a second
29    drv.play()  # play the effect
30    time.sleep(0.5)  # for 0.5 seconds
31    drv.stop()  # and then stop (if it's still running)
32    # Increment effect ID and wrap back around to 1.
33    effect_id += 1
34    if effect_id > 123:
35        effect_id = 1