Skip to content

Commit

Permalink
some accelometer tap demo and funcions
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Jul 12, 2016
1 parent 364eae6 commit d75c578
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Adafruit_CircuitPlayground.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ class Adafruit_CircuitPlayground {

uint16_t readCap(uint8_t p, uint8_t samples=10);

// Accelerometer
float motionX(void);
float motionY(void);
float motionZ(void);
void setAccelRange(lis3dh_range_t range) { lis.setRange(range); }
void setAccelTap(uint8_t c, uint8_t clickthresh)
{ lis.setClick(c, clickthresh, 10, 20, 255); }
uint8_t getAccelTap(void) { return lis.getClick(); }


// neopixels
void clearPixels(void) { strip.clear(); strip.show(); }
Expand Down
46 changes: 46 additions & 0 deletions examples/accelTap/accelTap.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

#include <Adafruit_CircuitPlayground.h>
// 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 120

void setup(void) {
while (!Serial);

Serial.begin(9600);
CircuitPlayground.begin();

CircuitPlayground.setAccelRange(LIS3DH_RANGE_2_G); // 2, 4, 8 or 16 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
CircuitPlayground.setAccelTap(1, CLICKTHRESHHOLD);

// have a procedure called when a tap is detected
attachInterrupt(digitalPinToInterrupt(7), tapTime, FALLING);
}

void tapTime(void) {
// do something :)
Serial.print("Tap! ");
Serial.println(millis()); // the time
}

void loop() {
/*
// *or* uncomment this for manual polling of tap data
uint8_t click = CircuitPlayground.getAccelTap();
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();
delay(100);
return;
*/
}

0 comments on commit d75c578

Please sign in to comment.