Liam McHale / Mbed 2 deprecated EmbeddQ2

Dependencies:   mbed MMA7660

Committer:
liammchale
Date:
Sat Aug 08 10:45:06 2020 +0000
Revision:
1:06020d654386
Parent:
0:ea609f08f075
Child:
2:434dcfb116db
embedded question 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
liammchale 0:ea609f08f075 1 #include "mbed.h"//preprosser demand
liammchale 0:ea609f08f075 2 #include "MMA7660.h"//preprocesser demand
liammchale 0:ea609f08f075 3
liammchale 0:ea609f08f075 4 #define PI 3.14159265//PI defined
liammchale 0:ea609f08f075 5
liammchale 0:ea609f08f075 6 Serial pc(USBTX,USBRX);//serial transmission to pc via USBTX, USBRX
liammchale 0:ea609f08f075 7 MMA7660 MMA(p28,p27);//IC2 pins associated with accelerometer
liammchale 0:ea609f08f075 8
liammchale 0:ea609f08f075 9 float calculateAngle(float x,float y,float z){
liammchale 0:ea609f08f075 10 float angle = 0;
liammchale 0:ea609f08f075 11 // calculate the angle from the formula given in the instructions
liammchale 0:ea609f08f075 12
liammchale 0:ea609f08f075 13 angle = (y*y) + (z*z);
liammchale 0:ea609f08f075 14 angle = sqrt (angle);
liammchale 0:ea609f08f075 15 angle = x/angle;
liammchale 0:ea609f08f075 16 angle = atan (angle);
liammchale 0:ea609f08f075 17 angle = angle *180/PI; //radians to degrees!
liammchale 0:ea609f08f075 18 return angle;
liammchale 0:ea609f08f075 19 }
liammchale 0:ea609f08f075 20
liammchale 0:ea609f08f075 21 int main(){
liammchale 0:ea609f08f075 22 while (1){
liammchale 0:ea609f08f075 23 pc.printf(" X%f Y%f Z%f angle%.2f degrees\r", MMA.x(),
liammchale 0:ea609f08f075 24 MMA.y(), MMA.z(), calculateAngle(MMA.x(), MMA.y(), MMA.z()));
liammchale 1:06020d654386 25 //i have used \r to repeat the function and keep the tera term tidy
liammchale 0:ea609f08f075 26 wait(1);
liammchale 0:ea609f08f075 27 }
liammchale 0:ea609f08f075 28 }