Frank Doherty
/
Interrupt
Interrupt Lab
Diff: main.cpp
- Revision:
- 1:82217c93a7dd
- Parent:
- 0:82470c7cda3a
--- a/main.cpp Fri May 24 14:58:16 2019 +0000 +++ b/main.cpp Fri May 24 15:31:59 2019 +0000 @@ -1,51 +1,27 @@ -#include "mbed.h" +//Using measured acceleration to run Led 2 and Led 3 on the Mbed// -Serial pc(USBTX, USBRX); -InterruptIn button1(p12); -InterruptIn button2(p13); -InterruptIn button3(p14); -InterruptIn button4(p15); -InterruptIn button5(p16); +#include "mbed.h" +#include "MMA7660.h" -int down=0; -int left=0; -int center=0; -int up=0; -int right=0; +Serial pc(USBTX, USBRX); //tx rx +MMA7660 MMA(p28, p27); -void down_check() - { - printf("Joystick is pressed towards Down direction\n\r"); - wait (2); - } -void left_check() - { - printf("Joystick is pressed towards Left direction\n\r"); - wait (2); - } -void center_check() - { - printf("Joystick is pressed towards Center direction\n\r"); - wait (2); - } -void up_check() - { - printf("Joystick is pressed towards Up direction\n\r"); - wait (2); - } -void right_check() - { - printf("Joystick is pressed towards Right direction\n\r"); - wait (2); - } - int main() - { - //timer_temp start(); - button1.rise (&down_check); - button2.rise (&left_check); - button3.rise (¢er_check); - button4.rise (&up_check); - button5.rise (&right_check); - - } - \ No newline at end of file +float calculateAngle (float x, float y, float z) +{ + float angle = 0; + + angle = (atan (x/ sqrt((y*y)+(z*z))*180/3.17); + + return angle; + + } + int main() + { + //if MMA.test connection () )// + + while (1) + { + print.f("x %f, y %f, z %f ang %f\n", MMA.x(), MMA.y(), MMA.z(), calculateAngle(MMA.x(),MMA.y(),MMA.z())); + wait(1); + } + }