Lab 3ES_ John Curran T00214119

Dependencies:   mbed MMA7660

Committer:
johnc89
Date:
Sat Apr 17 18:34:38 2021 +0000
Revision:
5:72d55b40feef
Parent:
4:efd9328bb9f0
Child:
6:50b706a10a68
Some Further Testing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 0:bd0546063b0a 1
Sissors 0:bd0546063b0a 2 #include "mbed.h"
Sissors 0:bd0546063b0a 3 #include "MMA7660.h"
johnc89 4:efd9328bb9f0 4 #include <stdio.h>
johnc89 4:efd9328bb9f0 5 #include <math.h>
johnc89 4:efd9328bb9f0 6 #define PI 3.14159265
johnc89 3:7380a26ac26f 7 Serial pc(USBTX,USBRX);// serial communications
Sissors 0:bd0546063b0a 8 MMA7660 MMA(p28, p27);
Sissors 0:bd0546063b0a 9
Sissors 0:bd0546063b0a 10 DigitalOut connectionLed(LED1);
johnc89 4:efd9328bb9f0 11
johnc89 5:72d55b40feef 12 float calculateAngle(float x, float y, float z, float val, float ret)
johnc89 5:72d55b40feef 13 {
johnc89 4:efd9328bb9f0 14 float angle =0;
johnc89 5:72d55b40feef 15
johnc89 5:72d55b40feef 16 val = 180.0 / PI;
johnc89 4:efd9328bb9f0 17
johnc89 5:72d55b40feef 18 ret = atan (x) * val;
johnc89 5:72d55b40feef 19 ret = atan (y) * val;
johnc89 5:72d55b40feef 20 ret = atan (z) * val;
johnc89 5:72d55b40feef 21 ret = ('atan (x) )/ (sqrt float pow(y) *(y) ) + sqrt float pow(z)* val');
johnc89 5:72d55b40feef 22 printf("The arc tangent of %lf is %lf degrees \n\r ", x, y, z, ret);
johnc89 5:72d55b40feef 23
johnc89 5:72d55b40feef 24
johnc89 5:72d55b40feef 25 return angle;
johnc89 4:efd9328bb9f0 26 }
Sissors 0:bd0546063b0a 27
johnc89 5:72d55b40feef 28 int main()
johnc89 5:72d55b40feef 29 {
Sissors 0:bd0546063b0a 30 if (MMA.testConnection())
Sissors 0:bd0546063b0a 31 connectionLed = 1;
johnc89 5:72d55b40feef 32
Sissors 0:bd0546063b0a 33 while(1) {
johnc89 4:efd9328bb9f0 34 float val;
johnc89 4:efd9328bb9f0 35 float ret;
johnc89 4:efd9328bb9f0 36 pc.printf ("%f, \r\n", calculateAngle (MMA.x(), MMA.y(), MMA.z(),val,ret ));
johnc89 3:7380a26ac26f 37 wait (0.5);
Sissors 0:bd0546063b0a 38 }
Sissors 0:bd0546063b0a 39
Sissors 0:bd0546063b0a 40 }