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.
main.cpp
- Committer:
- liammchale
- Date:
- 2020-08-08
- Revision:
- 0:ea609f08f075
- Child:
- 1:06020d654386
File content as of revision 0:ea609f08f075:
#include "mbed.h"//preprosser demand
#include "MMA7660.h"//preprocesser demand
#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);
angle = sqrt (angle);
angle = x/angle;
angle = atan (angle);
angle = angle *180/PI; //radians to degrees!
return angle;
}
int main(){
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()));
wait(1);
}
}