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 MMA8452 by
main.cpp
00001 #include "mbed.h" 00002 00003 I2C i2c(p9,p10); 00004 Serial pc(USBTX, USBRX); 00005 DigitalOut led1(LED1); 00006 DigitalOut led2(LED2); 00007 DigitalOut led3(LED3); 00008 00009 int main() { 00010 led1 = 0; 00011 led2 = 0; 00012 led3 = 0; 00013 char cmd[6]; 00014 char add[1]; 00015 char init[2]; 00016 add[0] = 0x01; 00017 init[0] = 0x2A; 00018 init[1] = 0x01; 00019 int number=0; 00020 i2c.frequency(40000); 00021 00022 wait(0.5); 00023 //init 00024 //set active mode 00025 while(i2c.write(0x3A,init,2)); 00026 led1 = 1; 00027 led2 = 1; 00028 led3 = 1; 00029 00030 //get analog data 00031 while(1) { 00032 //send procedure 00033 wait(0.07); 00034 switch(number){ 00035 case 0: 00036 if(i2c.write(0x3A,add,1) == 0){ 00037 number++; 00038 led1 = 1; 00039 }else{ 00040 number=0; 00041 led1 = 0; 00042 led2 = 0; 00043 led3 = 1; 00044 } 00045 break; 00046 case 1: 00047 if(i2c.read(0x3A,cmd,6) == 0){ 00048 number++; 00049 led2 = 1; 00050 }else{ 00051 number=0; 00052 led1 = 0; 00053 led2 = 0; 00054 led3 = 0; 00055 } 00056 break; 00057 case 2: 00058 //get analog data 00059 pc.printf("\r X = %d,Y = %d,Z = %d ",cmd[1],cmd[3],cmd[5]); 00060 led3 = 1; 00061 wait(0.5); 00062 led1 = 0; 00063 led2 = 0; 00064 led3 = 0; 00065 number=0; 00066 break; 00067 } 00068 } 00069 }
Generated on Wed Jul 13 2022 20:24:22 by
1.7.2
