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.
Fork of ADXL345_I2C by
main.cpp
00001 #include "ADXL345_I2C.h" 00002 00003 ADXL345_I2C accelerometer(p28, p27); 00004 Serial pc(USBTX, USBRX); 00005 Serial device(p9, p10); // tx, rx 00006 00007 //for LEDs----------------------------------------- 00008 DigitalOut debug1(LED1); //for debug 00009 DigitalOut debug2(LED2); //for debug 00010 DigitalOut debug3(LED3); //for debug 00011 DigitalOut debug4(LED4); //for debug 00012 //--------------------------------------------- 00013 00014 00015 int main() { 00016 pc.baud(9600); 00017 int readings[3] = {0, 0, 0}; 00018 char tmp; 00019 00020 while(1){ 00021 pc.printf("Starting ADXL345 test...\n"); 00022 wait(.001); 00023 pc.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID()); 00024 wait(.001); 00025 00026 // These are here to test whether any of the initialization fails. It will print the failure 00027 if (accelerometer.setPowerControl(0x00)){ 00028 pc.printf("didn't intitialize power control\n"); 00029 return 0; 00030 } 00031 //Full resolution, +/-16g, 4mg/LSB. 00032 wait(.001); 00033 00034 if(accelerometer.setDataFormatControl(0x0B)){ 00035 pc.printf("didn't set data format\n"); 00036 return 0; 00037 } 00038 wait(.001); 00039 00040 //3.2kHz data rate. 00041 if(accelerometer.setDataRate(ADXL345_3200HZ)){ 00042 pc.printf("didn't set data rate\n"); 00043 return 0; 00044 } 00045 wait(.001); 00046 00047 //Measurement mode. 00048 00049 if(accelerometer.setPowerControl(MeasurementMode)) { 00050 pc.printf("didn't set the power control to measurement\n"); 00051 return 0; 00052 } 00053 00054 while (1) { 00055 wait(0.1); 00056 accelerometer.getOutput(readings); 00057 int dice_number = 0; 00058 00059 if ((int16_t)readings[0]>200){ 00060 dice_number = 1; 00061 } 00062 else if ((int16_t)readings[0]<-200){ 00063 dice_number = 6; 00064 } 00065 else if ((int16_t)readings[1]>200){ 00066 dice_number = 2; 00067 } 00068 else if ((int16_t)readings[1]<-200){ 00069 dice_number = 5; 00070 } 00071 else if ((int16_t)readings[2]>200){ 00072 dice_number = 3; 00073 } 00074 else if ((int16_t)readings[2]<-200){ 00075 dice_number = 4; 00076 } 00077 00078 pc.printf("%i\r\n", dice_number); 00079 } 00080 00081 tmp = pc.getc(); 00082 00083 if(tmp == '0') { 00084 pc.putc(tmp); 00085 debug3 = 1; 00086 debug4 = 0; 00087 } else { 00088 pc.printf("Fuck You!!\r\n"); 00089 pc.printf("tmp : %d\r\n", tmp); 00090 debug4 = 1; 00091 debug3 = 0; 00092 } 00093 } 00094 00095 }
Generated on Wed Jul 13 2022 20:02:32 by
1.7.2
