■CurieIMU.shockDetected関数
CurieIMU.hライブラリのCurieIMU.shockDetected関数は、ショックが検出された場合にtrueを返します。
■使用例
CurieIMU.shockDetected関数を使ったArduinoIDEのプログラム例は図1の通りです。このプログラムを実行すると、Genuino101に衝撃が加わると図3の6方向それぞれについてCurieIMU.shockDetected関数によって衝撃の有無を判定し、衝撃が加わった軸と方向を図2の様にシリアルモニタ上に返します。
#include "CurieIMU.h" void setup() { Serial.begin(9600); // initialize Serial communication while (!Serial) ; // wait for serial port to connect.. /* Initialise the IMU */ CurieIMU.begin(); CurieIMU.attachInterrupt(eventCallback); /* Enable Shock Detection */ CurieIMU.setDetectionThreshold(CURIE_IMU_SHOCK, 1500); // 1.5g = 1500 mg CurieIMU.setDetectionDuration(CURIE_IMU_SHOCK, 50); // 50ms CurieIMU.interrupts(CURIE_IMU_SHOCK); Serial.println("IMU initialisation complete, waiting for events..."); } void loop() {} static void eventCallback(void) { if (CurieIMU.getInterruptStatus(CURIE_IMU_SHOCK)) { if (CurieIMU.shockDetected(X_AXIS, POSITIVE)) Serial.println("Negative shock detected on X-axis"); if (CurieIMU.shockDetected(X_AXIS, NEGATIVE)) Serial.println("Positive shock detected on X-axis"); if (CurieIMU.shockDetected(Y_AXIS, POSITIVE)) Serial.println("Negative shock detected on Y-axis"); if (CurieIMU.shockDetected(Y_AXIS, NEGATIVE)) Serial.println("Positive shock detected on Y-axis"); if (CurieIMU.shockDetected(Z_AXIS, POSITIVE)) Serial.println("Negative shock detected on Z-axis"); if (CurieIMU.shockDetected(Z_AXIS, NEGATIVE)) Serial.println("Positive shock detected on Z-axis"); } }
図1:プログラム例
図2:プログラム実行結果
■「CurieIMU.shockDetected(int axis, int direction)」のパラメータ
axis:ショック検出を確認する軸、表1に示すいずれかの値を設定する事が出来ます。
項目 | 内容 |
X_AXIS | X軸 |
Y_AXIS | Y軸 |
Z_AXIS | Z軸 |
direction:ショック検出を確認する方向、表2に示すいずれかの値を設定する事が出来ます。
項目 | 内容 |
POSITIVE | ゼロから正の軸値 |
NEGATIVE | ゼロから負の軸値 |
※XYZ軸検出方向について
Genuino101のXYZ検出方向はそれぞれ+-方向も含め図3の通り6方向です。
■その他関数
Curie IMUライブラリに関するその他関数については、コチラをご覧ください。
励みになりますのでよければクリック下さい(^o^)/