![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Cyber Physical Systems Mark Roche LAB 2
main.cpp
- Committer:
- mark_roche
- Date:
- 2022-05-11
- Revision:
- 1:3a0dea78e0c5
- Parent:
- 0:0d335e3eea24
File content as of revision 1:3a0dea78e0c5:
//____Industry 4.0: Cyber Phys Systs-51296_______ //____Lab 2 Mark Roche_____ #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); } }