|
12 | 12 | See examples in the examples directory.
|
13 | 13 |
|
14 | 14 | * Author(s): Tony DiCola
|
| 15 | +
|
| 16 | +Implementation Notes |
| 17 | +-------------------- |
| 18 | +
|
| 19 | +**Hardware:** |
| 20 | +
|
| 21 | +* `Adafruit LIS3DH Triple-Axis Accelerometer Breakout |
| 22 | + <https://www.adafruit.com/product/2809>`_ |
| 23 | +
|
| 24 | +* `Circuit Playground Express <https://www.adafruit.com/product/3333>`_ |
| 25 | +
|
| 26 | +**Software and Dependencies:** |
| 27 | +
|
| 28 | +* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: |
| 29 | + https://github.com/adafruit/circuitpython/releases |
| 30 | +* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice |
15 | 31 | """
|
16 | 32 |
|
17 | 33 | import time
|
@@ -149,16 +165,20 @@ def acceleration(self):
|
149 | 165 | return x, y, z
|
150 | 166 |
|
151 | 167 | def shake(self, shake_threshold=30, avg_count=10, total_delay=0.1):
|
152 |
| - """Detect when the accelerometer is shaken. Optional parameters: |
153 |
| - shake_threshold - Increase or decrease to change shake sensitivity. This |
154 |
| - requires a minimum value of 10. 10 is the total |
155 |
| - acceleration if the board is not moving, therefore |
156 |
| - anything less than 10 will erroneously report a constant |
157 |
| - shake detected. (Default 30) |
158 |
| - avg_count - The number of readings taken and used for the average |
159 |
| - acceleration. (Default 10) |
160 |
| - total_delay - The total time in seconds it takes to obtain avg_count |
161 |
| - readings from acceleration. (Default 0.1) |
| 168 | + """ |
| 169 | + Detect when the accelerometer is shaken. Optional parameters: |
| 170 | +
|
| 171 | + :param shake_threshold: Increase or decrease to change shake sensitivity. This |
| 172 | + requires a minimum value of 10. 10 is the total |
| 173 | + acceleration if the board is not moving, therefore |
| 174 | + anything less than 10 will erroneously report a constant |
| 175 | + shake detected. (Default 30) |
| 176 | +
|
| 177 | + :param avg_count: The number of readings taken and used for the average |
| 178 | + acceleration. (Default 10) |
| 179 | +
|
| 180 | + :param total_delay: The total time in seconds it takes to obtain avg_count |
| 181 | + readings from acceleration. (Default 0.1) |
162 | 182 | """
|
163 | 183 | shake_accel = (0, 0, 0)
|
164 | 184 | for _ in range(avg_count):
|
@@ -204,45 +224,50 @@ def read_adc_mV(self, adc): # pylint: disable=invalid-name
|
204 | 224 |
|
205 | 225 | @property
|
206 | 226 | def tapped(self):
|
207 |
| - """True if a tap was detected recently. Whether its a single tap or double tap is |
208 |
| - determined by the tap param on ``set_tap``. ``tapped`` may be True over |
209 |
| - multiple reads even if only a single tap or single double tap occurred if the |
210 |
| - interrupt (int) pin is not specified. |
| 227 | + """ |
| 228 | + True if a tap was detected recently. Whether its a single tap or double tap is |
| 229 | + determined by the tap param on ``set_tap``. ``tapped`` may be True over |
| 230 | + multiple reads even if only a single tap or single double tap occurred if the |
| 231 | + interrupt (int) pin is not specified. |
211 | 232 |
|
212 |
| - The following example uses ``i2c`` and specifies the interrupt pin: |
| 233 | + The following example uses ``i2c`` and specifies the interrupt pin: |
213 | 234 |
|
214 |
| - .. code-block:: python |
| 235 | + .. code-block:: python |
215 | 236 |
|
216 |
| - import adafruit_lis3dh |
217 |
| - import digitalio |
| 237 | + import adafruit_lis3dh |
| 238 | + import digitalio |
218 | 239 |
|
219 |
| - i2c = busio.I2C(board.SCL, board.SDA) |
220 |
| - int1 = digitalio.DigitalInOut(board.D11) # pin connected to interrupt |
221 |
| - lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1) |
222 |
| - lis3dh.range = adafruit_lis3dh.RANGE_8_G |
| 240 | + i2c = busio.I2C(board.SCL, board.SDA) |
| 241 | + int1 = digitalio.DigitalInOut(board.D11) # pin connected to interrupt |
| 242 | + lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1) |
| 243 | + lis3dh.range = adafruit_lis3dh.RANGE_8_G |
223 | 244 |
|
224 |
| - """ |
| 245 | + """ |
225 | 246 | if self._int1 and not self._int1.value:
|
226 | 247 | return False
|
227 | 248 | raw = self._read_register_byte(REG_CLICKSRC)
|
228 | 249 | return raw & 0x40 > 0
|
229 | 250 |
|
230 | 251 | def set_tap(self, tap, threshold, *,
|
231 | 252 | time_limit=10, time_latency=20, time_window=255, click_cfg=None):
|
232 |
| - """Set the tap detection parameters. |
233 |
| -
|
234 |
| - .. note:: Tap related registers are called CLICK_ in the datasheet. |
235 |
| -
|
236 |
| - :param int tap: 0 to disable tap detection, 1 to detect only single |
237 |
| - taps, and 2 to detect only double taps. |
238 |
| - :param int threshold: A threshold for the tap detection. The higher the value |
239 |
| - the less sensitive the detection. This changes based on the accelerometer |
240 |
| - range. Good values are 5-10 for 16G, 10-20 for 8G, 20-40 for 4G, and 40-80 for |
241 |
| - 2G. |
242 |
| - :param int time_limit: TIME_LIMIT register value (default 10). |
243 |
| - :param int time_latency: TIME_LATENCY register value (default 20). |
244 |
| - :param int time_window: TIME_WINDOW register value (default 255). |
245 |
| - :param int click_cfg: CLICK_CFG register value.""" |
| 253 | + """ |
| 254 | + The tap detection parameters. |
| 255 | +
|
| 256 | + .. note:: Tap related registers are called ``CLICK_`` in the datasheet. |
| 257 | +
|
| 258 | + :param int tap: 0 to disable tap detection, 1 to detect only single |
| 259 | + taps, and 2 to detect only double taps. |
| 260 | +
|
| 261 | + :param int threshold: A threshold for the tap detection. The higher the value |
| 262 | + the less sensitive the detection. This changes based on |
| 263 | + the accelerometer range. Good values are 5-10 for 16G, |
| 264 | + 10-20 for 8G, 20-40 for 4G, and 40-80 for 2G. |
| 265 | +
|
| 266 | + :param int time_limit: TIME_LIMIT register value (default 10). |
| 267 | + :param int time_latency: TIME_LATENCY register value (default 20). |
| 268 | + :param int time_window: TIME_WINDOW register value (default 255). |
| 269 | + :param int click_cfg: CLICK_CFG register value. |
| 270 | + """ |
246 | 271 | if (tap < 0 or tap > 2) and click_cfg is None:
|
247 | 272 | raise ValueError('Tap must be 0 (disabled), 1 (single tap), or 2 (double tap)!')
|
248 | 273 | if threshold > 127 or threshold < 0:
|
|
0 commit comments