source: trunk/Arduino/libraries/Adafruit_Circuit_Playground/examples/accelTap/accelTap.ino @ 7

Last change on this file since 7 was 3, checked in by markus, 7 years ago

Setup project structure

File size: 1.4 KB
Line 
1#include <Adafruit_CircuitPlayground.h>
2#include <Wire.h>
3#include <SPI.h>
4
5// Adjust this number for the sensitivity of the 'click' force
6// this strongly depend on the range! for 16G, try 5-10
7// for 8G, try 10-20. for 4G try 20-40. for 2G try 40-80
8#define CLICKTHRESHHOLD 120
9
10void setup(void) {
11  while (!Serial);
12 
13  Serial.begin(9600);
14  CircuitPlayground.begin();
15 
16  CircuitPlayground.setAccelRange(LIS3DH_RANGE_2_G);   // 2, 4, 8 or 16 G!
17 
18  // 0 = turn off click detection & interrupt
19  // 1 = single click only interrupt output
20  // 2 = double click only interrupt output, detect single click
21  // Adjust threshhold, higher numbers are less sensitive
22  CircuitPlayground.setAccelTap(1, CLICKTHRESHHOLD);
23 
24  // have a procedure called when a tap is detected
25  attachInterrupt(digitalPinToInterrupt(CPLAY_LIS3DH_INTERRUPT), tapTime, FALLING);
26}
27
28void tapTime(void) {
29  // do something :)
30   Serial.print("Tap! ");
31   Serial.println(millis()); // the time
32}
33
34void loop() {
35/*
36 // *or* uncomment this for manual polling of tap data
37  uint8_t click = CircuitPlayground.getAccelTap();
38  if (click == 0) return;
39  if (! (click & 0x30)) return;
40  Serial.print("Click detected (0x"); Serial.print(click, HEX); Serial.print("): ");
41  if (click & 0x10) Serial.print(" single click");
42  if (click & 0x20) Serial.print(" double click");
43  Serial.println();
44
45  delay(100);
46  return;
47*/
48}
Note: See TracBrowser for help on using the repository browser.