-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtapdemo.ino
87 lines (71 loc) · 2.5 KB
/
tapdemo.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Basic demo for tap/doubletap readings from Adafruit LIS3DH
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
// Used for software SPI
#define LIS3DH_CLK 13
#define LIS3DH_MISO 12
#define LIS3DH_MOSI 11
// Used for hardware & software SPI
#define LIS3DH_CS 10
// software SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);
// hardware SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS);
// I2C
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
// #define Serial SerialUSB
#endif
// Adjust this number for the sensitivity of the 'click' force
// this strongly depend on the range! for 16G, try 5-10
// for 8G, try 10-20. for 4G try 20-40. for 2G try 40-80
#define CLICKTHRESHHOLD 40
void setup(void) {
#ifndef ESP8266
while (!Serial); // will pause Zero, Leonardo, etc until serial console opens
#endif
Serial.begin(9600);
Serial.println("Adafruit LIS3DH Tap Test!");
if (! lis.begin(0x18)) { // change this to 0x19 for alternative i2c address
Serial.println("Couldnt start");
while (1);
}
Serial.println("LIS3DH found!");
lis.setRange(LIS3DH_RANGE_4_G); // 2, 4, 8 or 16 G!
Serial.print("Range = "); Serial.print(2 << lis.getRange());
Serial.println("G");
// 0 = turn off click detection & interrupt
// 1 = single click only interrupt output
// 2 = double click only interrupt output, detect single click
// Adjust threshhold, higher numbers are less sensitive
lis.setClick(2, CLICKTHRESHHOLD);
delay(100);
}
int check = 0;
void loop() {
/*uint8_t click = lis.getClick();
if (click == 0) return;
if (! (click & 0x30)) return;
Serial.print("Click detected (0x"); Serial.print(click, HEX); Serial.print("): ");
if (click & 0x10) Serial.print(" single click");
if (click & 0x20) Serial.print(" double click");
Serial.println();
*/
while (check == 0){
uint8_t click = lis.getClick();
if (click == 0){} //do nothing
else if (! (click & 0x30)) {}//Do nothing
if (click & 0x10) Serial.println(" single click");
if (click & 0x20){
Serial.println(" double click || Check now 1");
check = 1;
}
}
check = 0;
Serial.println("Check now 0");
Serial.println("Next");
delay(200);
}