|
LED插到13脚上,轻敲桌子就可以控制LED啦
源码:
[mw_shl_code=cpp,true]#include "CurieIMU.h"
bool state=false;
void setup() {
pinMode(13,OUTPUT);
Serial.begin(9600);
// while(!Serial) ;
CurieIMU.begin();
CurieIMU.attachInterrupt(eventCallback);
// Increase Accelerometer range to allow detection of stronger taps (< 16g)
CurieIMU.setAccelerometerRange(32);
CurieIMU.setAccelerometerRate(1600);
// Reduce threshold to allow detection of weaker taps (>= 100mg)
CurieIMU.setDetectionThreshold(CURIE_IMU_TAP, 100);
// Enable Tap detection
CurieIMU.interrupts(CURIE_IMU_TAP);
Serial.println("IMU initialization complete, waiting for events...");
}
void loop() {
}
static void eventCallback()
{
if (CurieIMU.getInterruptStatus(CURIE_IMU_TAP)) {
if (CurieIMU.tapDetected(X_AXIS, NEGATIVE))
Serial.println("Tap detected on negative X-axis");
if (CurieIMU.tapDetected(X_AXIS, POSITIVE))
Serial.println("Tap detected on positive X-axis");
if (CurieIMU.tapDetected(Y_AXIS, NEGATIVE))
Serial.println("Tap detected on negative Y-axis");
if (CurieIMU.tapDetected(Y_AXIS, POSITIVE))
Serial.println("Tap detected on positive Y-axis");
if (CurieIMU.tapDetected(Z_AXIS, NEGATIVE))
Serial.println("Tap detected on negative Z-axis");
if (CurieIMU.tapDetected(Z_AXIS, POSITIVE))
Serial.println("Tap detected on positive Z-axis");
state =!state;
digitalWrite(13,state);
}
}
[/mw_shl_code]
|
|