ADXL375_i2c(FIFO supported.) test program.

Dependencies:   mbed ADXL375_i2c

Committer:
ohtsuka
Date:
Thu Jun 24 03:00:58 2021 +0000
Revision:
0:f4d49f9b930c
support FIFO.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ohtsuka 0:f4d49f9b930c 1 #include "mbed.h"
ohtsuka 0:f4d49f9b930c 2 #include "ADXL375_i2c.h"
ohtsuka 0:f4d49f9b930c 3
ohtsuka 0:f4d49f9b930c 4 Serial pc(USBTX, USBRX, 115200);
ohtsuka 0:f4d49f9b930c 5 I2C i2c(p9, p10);
ohtsuka 0:f4d49f9b930c 6 ADXL375_i2c ADXL375(i2c, ADXL375_i2c::ALT_ADDRESS_HIGH);
ohtsuka 0:f4d49f9b930c 7
ohtsuka 0:f4d49f9b930c 8 float acc[3];
ohtsuka 0:f4d49f9b930c 9
ohtsuka 0:f4d49f9b930c 10
ohtsuka 0:f4d49f9b930c 11 void setup();
ohtsuka 0:f4d49f9b930c 12
ohtsuka 0:f4d49f9b930c 13
ohtsuka 0:f4d49f9b930c 14 int main(){
ohtsuka 0:f4d49f9b930c 15 setup();
ohtsuka 0:f4d49f9b930c 16
ohtsuka 0:f4d49f9b930c 17 // 開始直後にFIFOに入った分をクリア
ohtsuka 0:f4d49f9b930c 18 for(int i=0; i<ADXL375.getFifoEntries(); i++) {
ohtsuka 0:f4d49f9b930c 19 ADXL375.getOutput(acc);
ohtsuka 0:f4d49f9b930c 20 }
ohtsuka 0:f4d49f9b930c 21
ohtsuka 0:f4d49f9b930c 22 while(1){
ohtsuka 0:f4d49f9b930c 23 int entries = ADXL375.getFifoEntries();
ohtsuka 0:f4d49f9b930c 24 if(entries > 0) {
ohtsuka 0:f4d49f9b930c 25 pc.printf("\n%2d: ", entries );
ohtsuka 0:f4d49f9b930c 26 for(int i=0; i<entries; i++) {
ohtsuka 0:f4d49f9b930c 27 ADXL375.getOutput(acc);
ohtsuka 0:f4d49f9b930c 28 pc.printf("%.2f,%.2f,%.2f/ ",acc[0], acc[1], acc[2]);
ohtsuka 0:f4d49f9b930c 29 }
ohtsuka 0:f4d49f9b930c 30 pc.printf("\n");
ohtsuka 0:f4d49f9b930c 31 } else {
ohtsuka 0:f4d49f9b930c 32 pc.printf(".");
ohtsuka 0:f4d49f9b930c 33 }
ohtsuka 0:f4d49f9b930c 34 wait(0.1); // FIFOの効果を見るため、わざと遅めにループする
ohtsuka 0:f4d49f9b930c 35 }
ohtsuka 0:f4d49f9b930c 36 }
ohtsuka 0:f4d49f9b930c 37
ohtsuka 0:f4d49f9b930c 38
ohtsuka 0:f4d49f9b930c 39
ohtsuka 0:f4d49f9b930c 40 void setup(){
ohtsuka 0:f4d49f9b930c 41
ohtsuka 0:f4d49f9b930c 42 ADXL375.setDataRate(ADXL375_25HZ);
ohtsuka 0:f4d49f9b930c 43 if(ADXL375.whoAmI() == 1){
ohtsuka 0:f4d49f9b930c 44 pc.printf("ADXL375 : OK\r\n");
ohtsuka 0:f4d49f9b930c 45 }
ohtsuka 0:f4d49f9b930c 46 else{
ohtsuka 0:f4d49f9b930c 47 pc.printf("ADXL375 : NG.....\r\n");
ohtsuka 0:f4d49f9b930c 48 }
ohtsuka 0:f4d49f9b930c 49 ADXL375.offset(-0.2f, -0.4f, 0.6f);
ohtsuka 0:f4d49f9b930c 50 ADXL375.setFifoMode(true);
ohtsuka 0:f4d49f9b930c 51 }