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
Revision 0:904e837fccc5, committed 2012-11-28
- Comitter:
- matsu
- Date:
- Wed Nov 28 16:55:32 2012 +0000
- Child:
- 1:0c1dd02be97a
- Commit message:
- this is sample source of MMA8452
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Nov 28 16:55:32 2012 +0000
@@ -0,0 +1,71 @@
+#include "mbed.h"
+
+I2C i2c(p9,p10);
+Serial pc(USBTX, USBRX);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+
+int main() {
+ led1 = 0;
+ led2 = 0;
+ led3 = 0;
+ char cmd[6];
+ char add[1];
+ char init[2];
+ add[0] = 0x01;
+ init[0] = 0x2A;
+ init[1] = 0x01;
+ int number=0;
+ i2c.frequency(40000);
+
+ wait(0.5);
+ //init
+ //set active mode
+ while(i2c.write(0x3A,init,2));
+ led1 = 1;
+ led2 = 1;
+ led3 = 1;
+
+ //get analog data
+ while(1) {
+ //send procedure
+ wait(0.07);
+ switch(number){
+ case 0:
+// i2c.start();
+ if(i2c.write(0x3A,add,1) == 0){
+ number++;
+ led1 = 1;
+ }else{
+ number=0;
+ led1 = 0;
+ led2 = 0;
+ led3 = 1;
+ }
+ break;
+ case 1:
+// i2c.start();
+ if(i2c.read(0x3A,cmd,6) == 0){
+ number++;
+ led2 = 1;
+ }else{
+ number=0;
+ led1 = 0;
+ led2 = 0;
+ led3 = 0;
+ }
+ break;
+ case 2:
+// pc.printf("\r cmd1 = %d,cmd2 = %d,cmd3 = %d ",((cmd[0]<<4)+(cmd[1]>>4)),((cmd[2]<<4)+(cmd[3]>>4)),((cmd[4]<<4)+(cmd[5]>>4)));
+ pc.printf("\r X = %d,Y = %d,Z = %d ",cmd[1],cmd[3],cmd[5]);
+ led3 = 1;
+ wait(0.5);
+ led1 = 0;
+ led2 = 0;
+ led3 = 0;
+ number=0;
+ break;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Nov 28 16:55:32 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ed12d17f06 \ No newline at end of file
