
Prints Pitch & Slope Angles
Revision 0:885c71e3dd67, committed 2019-08-07
- Comitter:
- t00203814
- Date:
- Wed Aug 07 01:11:25 2019 +0000
- Commit message:
- T00203814
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA7660.lib Wed Aug 07 01:11:25 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/Sissors/code/MMA7660/#36a163511e34
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Aug 07 01:11:25 2019 +0000 @@ -0,0 +1,30 @@ +#include "mbed.h"//includes mbed header +#include "MMA7660.h"//includes MMA7660 header + +#define PI 3.14159265// defines PI as 3.14159265 + +Serial pc(USBTX, USBRX);// sets up serial connection to PC +MMA7660 MMA(p28, p27);// declares MMA7660 on P27 & p28 and calles them MMA + + +float calculateAngle(float x, float y, float z) {// sets up a float values called calculateAngler, x, y & z +float angle = 0;// iniates a float value called angle and sets it to zero + angle = (atan(x/sqrt((y*y)+(z*z)))*180/PI);//Calculating the pitch from formular in instructions + pc.printf("Pitch angle is %.3f degrees\n\n\r",angle); + angle = (atan(y/sqrt((x*x)+(z*z)))*180/PI);//Calculating the roll from formular in instructions + pc.printf("Roll angle is %.3f degrees\n\n\r",angle); + wait(3);// waits 3 seconds + return angle; +} + + + +int main() { + + while(1) { + pc.printf(" X %f Y %f Z %f angle %.2f degrees \n", MMA.x(), MMA.y(), MMA.z(), calculateAngle(MMA.x(), MMA.y(), MMA.z()));// prints to Pc + wait(1);// waits 1 second + +} + } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Aug 07 01:11:25 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file