Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include <ADXL345.h> 00003 00004 #define MOSI D11 00005 #define MISO D12 00006 #define SCK D13 00007 #define CS D10 00008 00009 DigitalOut led_1(A2); 00010 DigitalOut led_2(A3); 00011 ADXL345 aMeter(MOSI,MISO,SCK,CS); 00012 Serial pc(USBTX, USBRX,230400); 00013 00014 void aSetup() 00015 { 00016 //pc.printf("Device ID is: 0x%02x\n", aMeter.getDevId()); 00017 aMeter.setPowerControl(0x00);//スタンバイモードに移行してデバイスを設定します 00018 aMeter.setDataFormatControl(0x0B);//フル解像度、+/- 16g、4mg / LSB。 00019 aMeter.setDataRate(ADXL345_3200HZ);// 3.2kHzのデータレート。 00020 aMeter.setPowerControl(0x08);//測定モード。 00021 } 00022 00023 int main() 00024 { 00025 aSetup(); 00026 led_1=1; 00027 int max=0,n=0,xyz[3]= {0,0,0};//読み取りXYZ 00028 while (1) { 00029 //wait(0.05); 00030 aMeter.getOutput(xyz);//xyz取得 00031 max=0; 00032 for(int i=0; i<100; i++) { 00033 n=abs(xyz[2]-240); 00034 if(n>max)max=n; 00035 wait(0.001); 00036 } 00037 if(max>80) { 00038 led_1=0; 00039 } 00040 if(max>20) { 00041 led_2=1; 00042 } else { 00043 led_2=0; 00044 led_1=1; 00045 } 00046 pc.printf("%i,200\n",(int16_t)xyz[2]-240);//xyz表示 00047 } 00048 }
Generated on Wed Jul 27 2022 09:16:32 by
1.7.2