加速度計からの外部割り込みを使用する必要があります。したがって、センサーモジュールがそのような割り込み機能を提供することに注意する必要があります。適切なモジュールは、たとえば、 Adafruit のI2C/SPI (ADXL チップに基づく) 付きの 3 軸加速度計で、17.50 ドルです。
さらに、割り込みピンを備えた Arduino が必要です。ほとんどの Arduino には、少なくとも 2 つの割り込みピン (番号 0 (デジタル ピン 2) と 1 (デジタル ピン 3)) があります。
PKMCは、加速度計で Arduino を中断するために必要な手順を次のように構成しました。
- ADXL 割り込みピン 1 を Arduino ピン 2 またはピン 3 に接続します。
- 加速度計のパラメータを設定します (例: )
//set ADXL interrupts
//enable single tap interrupt
//writeRegister(ADXL345_REG_INT_ENABLE, 0b01000000);
//enable single and double tap interrupt
writeRegister(ADXL345_REG_INT_ENABLE, 0b01100000);
//map all interrupts to pin1
writeRegister(ADXL345_REG_INT_MAP, 0b00000000);
// single tap configuration
writeRegister(ADXL345_REG_DUR, 0x1F); // 625us/LSB
writeRegister(ADXL345_REG_THRESH_TAP, 48);
writeRegister(ADXL345_REG_TAP_AXES, 0b111); // enable tap detection on x,y,z axes
//double tap configuration
writeRegister(ADXL345_REG_LATENT, 0x50);
writeRegister(ADXL345_REG_WINDOW, 0xff);
- セットアップ コードで Arduino INT0 (interrupt0) (またはピン 3 を選択した場合は INT1 (interrupt0) に) を割り当てます。
attachInterrupt(0, accelInterrupt, RISING);
- メインループの前にINT0割り込みルーチンを書く
void accelInterrupt(){
//...
}
加速度計と neopixels を使用した例(およびコード) を提供します。
この例が役立つと確信しています。