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
- Committer:
- matsu
- Date:
- 2012-11-28
- Revision:
- 0:904e837fccc5
- Child:
- 1:0c1dd02be97a
File content as of revision 0:904e837fccc5:
#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; } } }