m3 accel

Dependencies:   MMA7660 mbed

Fork of Serial_HelloWorld_Mbed by mbed official

main.cpp

Committer:
PosztosAlex
Date:
2017-04-05
Revision:
1:ad701230bd53
Parent:
0:879aa9d0247b

File content as of revision 1:ad701230bd53:

#include "mbed.h"
#include "MMA7660.h"

MMA7660 MMA(p28, p27);
Serial pc(USBTX, USBRX); // tx, rx
 DigitalOut led(LED1);
 DigitalIn acc(p14);
 
int main() {
    double x= 0,y=0,z=0;
    double xr= 0,yr=0,zr=0;
    int i; int n = 50;
    while(1) {
        
        for(i = 0; i<n; i++)
        {
            x = x + MMA.x() ;
            y = y + MMA.y() ;
            z = z + MMA.z() ;
        }
        x = x / n;
        y = y /  n ;
        z = z /  n;
        led=acc;
        if(acc)
        {
            yr = y;
            xr = x;
            zr=z;
        }
        
        x -= xr;
        y -= yr;
        z -= zr;
        pc.printf("%f,%f,%f\n",x,y,z);
        wait_ms(5);
    }
}