embedded q2

Dependencies:   mbed MMA7660

main.cpp

Committer:
liammchale
Date:
2020-08-08
Revision:
3:495bbb3d9e61
Parent:
2:434dcfb116db

File content as of revision 3:495bbb3d9e61:

#include "mbed.h"//preprosser command
#include "MMA7660.h"//preprocesser command

#define PI 3.14159265//PI defined 

Serial pc(USBTX,USBRX);//serial transmission to pc via USBTX, USBRX
MMA7660 MMA(p28,p27);//IC2 pins associated with accelerometer

float calculateAngle(float x,float y,float z){
    float angle = 0;
// calculate the angle from the formula given in the instructions

angle = (y*y) + (z*z);//bottom of the division line
angle = sqrt (angle);//square root
angle = x/angle;
angle = atan (angle);//arctan of angle
angle = angle *180/PI; //radians to degrees!
return angle;
}

int main(){//main program
    while (1){
        pc.printf("    X%f     Y%f      Z%f     angle%.2f degrees\r", MMA.x(), 
        MMA.y(), MMA.z(), calculateAngle(MMA.x(), MMA.y(), MMA.z()));
        //i have used \r to repeat the function and keep the tera term tidy
    wait(1);//wait 1 second
    }
}