
Calculate angle
Revision 0:7c1f435ce121, committed 2021-08-21
- Comitter:
- t00214916
- Date:
- Sat Aug 21 22:22:44 2021 +0000
- Commit message:
- Calculate angle
Changed in this revision
diff -r 000000000000 -r 7c1f435ce121 MMA7660.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA7660.lib Sat Aug 21 22:22:44 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/Sissors/code/MMA7660/#36a163511e34
diff -r 000000000000 -r 7c1f435ce121 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Aug 21 22:22:44 2021 +0000 @@ -0,0 +1,31 @@ +#include "mbed.h" +#include "MMA7660.h" +#define M_PI 3.14 // Giving PI a value +MMA7660 MMA (p27,p27); // Sensor class + +Serial pc (USBTX, USBRX); + +float calculateAngle(float x, float y, float z); +// The code I found to convert rad to angle + float rad_to_deg = (180/M_PI); + float AngleRad = atan(x / (sqrt (pow(y,2) + pow(z,2)))); + float angle = AngleRad * rad_to_deg; + return angle; + +} + +int main() +{ + if (MMA.testConnection()) // Test connection + printf("Working\r\n"); + + else + printf("Not working\r\n"); + + while(1) { // Calculate the angle using the sensor + float angle = calculateAngle(MMA.x(), MMA.y(), MMA.z()); + printf("Angle = %f Degrees\r\n", angle); + wait(3); + } + } +} \ No newline at end of file
diff -r 000000000000 -r 7c1f435ce121 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Aug 21 22:22:44 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file