STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
tapdemo.ino
Go to the documentation of this file.
1// Basic demo for tap/doubletap readings from Adafruit LIS3DH
2
3#include <Wire.h>
4#include <SPI.h>
5#include <Adafruit_LIS3DH.h>
6#include <Adafruit_Sensor.h>
7
8// Used for software SPI
9#define LIS3DH_CLK 13
10#define LIS3DH_MISO 12
11#define LIS3DH_MOSI 11
12// Used for hardware & software SPI
13#define LIS3DH_CS 10
14
15// software SPI
16//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);
17// hardware SPI
18//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS);
19// I2C
21
22// Adjust this number for the sensitivity of the 'click' force
23// this strongly depend on the range! for 16G, try 5-10
24// for 8G, try 10-20. for 4G try 20-40. for 2G try 40-80
25#define CLICKTHRESHHOLD 80
26
27void setup(void) {
28#ifndef ESP8266
29 while (!Serial) yield(); // will pause Zero, Leonardo, etc until serial console opens
30#endif
31
32 Serial.begin(9600);
33 Serial.println("Adafruit LIS3DH Tap Test!");
34
35 if (! lis.begin(0x18)) { // change this to 0x19 for alternative i2c address
36 Serial.println("Couldnt start");
37 while (1) yield();
38 }
39 Serial.println("LIS3DH found!");
40
41 lis.setRange(LIS3DH_RANGE_2_G); // 2, 4, 8 or 16 G!
42
43 Serial.print("Range = "); Serial.print(2 << lis.getRange());
44 Serial.println("G");
45
46 // 0 = turn off click detection & interrupt
47 // 1 = single click only interrupt output
48 // 2 = double click only interrupt output, detect single click
49 // Adjust threshhold, higher numbers are less sensitive
50 lis.setClick(2, CLICKTHRESHHOLD);
51 delay(100);
52}
53
54
55void loop() {
56 uint8_t click = lis.getClick();
57 if (click == 0) return;
58 if (! (click & 0x30)) return;
59 Serial.print("Click detected (0x"); Serial.print(click, HEX); Serial.print("): ");
60 if (click & 0x10) Serial.print(" single click");
61 if (click & 0x20) Serial.print(" double click");
62 Serial.println();
63
64 delay(100);
65 return;
66}
This is a library for the Adafruit LIS3DH Accel breakout board.
@ LIS3DH_RANGE_2_G
static SerialStub Serial
Definition Arduino.h:128
#define HEX
Definition Arduino.h:24
Adafruit_LIS3DH lis
Definition acceldemo.ino:23
void delay(int ms)
Class that stores state and functions for interacting with Adafruit_LIS3DH.
void setup(void)
Definition tapdemo.ino:27
#define CLICKTHRESHHOLD
Definition tapdemo.ino:25
void loop()
Definition tapdemo.ino:55