david ta
/
MMA845X
this is sample source of MMA845X
Fork of MMA8452 by
Revision 2:262986634636, committed 2014-03-25
- Comitter:
- comptuzus
- Date:
- Tue Mar 25 10:58:05 2014 +0000
- Parent:
- 1:0c1dd02be97a
- Commit message:
- modification of the address for mma845x;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Nov 28 17:05:31 2012 +0000 +++ b/main.cpp Tue Mar 25 10:58:05 2014 +0000 @@ -5,8 +5,10 @@ DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); +DigitalOut led4(LED4); int main() { + led4 = 1; led1 = 0; led2 = 0; led3 = 0; @@ -22,7 +24,7 @@ wait(0.5); //init //set active mode - while(i2c.write(0x3A,init,2)); + while(i2c.write(0x38,init,2)); led1 = 1; led2 = 1; led3 = 1; @@ -33,31 +35,41 @@ wait(0.07); switch(number){ case 0: - if(i2c.write(0x3A,add,1) == 0){ + if(i2c.write(0x38,add,1) == 0){ number++; - led1 = 1; + //led1 = 1; }else{ number=0; - led1 = 0; - led2 = 0; - led3 = 1; + //led1 = 0; + //led2 = 0; + //led3 = 1; } break; case 1: - if(i2c.read(0x3A,cmd,6) == 0){ + if(i2c.read(0x38,cmd,6) == 0){ number++; - led2 = 1; + //led2 = 1; }else{ number=0; - led1 = 0; - led2 = 0; - led3 = 0; + //led1 = 0; + //led2 = 0; + //led3 = 0; } break; case 2: //get analog data - pc.printf("\r X = %d,Y = %d,Z = %d ",cmd[1],cmd[3],cmd[5]); - led3 = 1; + //pc.printf("\r X = %d,Y = %d,Z = %d ",cmd[1],cmd[3],cmd[5]); + //led3 = 1; + led1 = 0; + led2 = 0; + led3 = 0; + if (cmd[1] > cmd[3]){ + led1 = 1; + }else if(cmd[3] > cmd[5]){ + led2 = 1; + }else{ + led3 = 1; + } wait(0.5); led1 = 0; led2 = 0;