![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Cyber Physical Systems Mark Roche LAB 2
Diff: main.cpp
- Revision:
- 0:0d335e3eea24
- Child:
- 1:3a0dea78e0c5
diff -r 000000000000 -r 0d335e3eea24 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed May 11 17:09:09 2022 +0000 @@ -0,0 +1,34 @@ + +#include "mbed.h" +#include "MMA7660.h" + +MMA7660 MMA(p28, p27); + +#define PI 3.14159265 + +DigitalOut connectionLed(LED1); + +float calculateAngle(float x, float y, float z){ + float angle = 0; + + float top_part = x; + float bott_part = sqrt((y*y)+(z*z)); + float res = atan(top_part/bott_part); + float val = 180.0 / PI; + angle = res * val; + return angle; +} + + + +int main() { + if (MMA.testConnection()) + connectionLed = 1; + printf("\r\n\n"); + while(1) { + float res = calculateAngle(MMA.x(), MMA.y(), MMA.z()); + printf("angle = %f \r", res); + wait(1); + +} +} \ No newline at end of file