![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
lab question 2
Dependencies: mbed C12832_lcd MMA7660 ttmath
main.cpp@0:7cd973be7a0a, 2019-05-21 (annotated)
- Committer:
- niallmoyvane
- Date:
- Tue May 21 11:54:31 2019 +0000
- Revision:
- 0:7cd973be7a0a
lab question 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
niallmoyvane | 0:7cd973be7a0a | 1 | #include "mbed.h" |
niallmoyvane | 0:7cd973be7a0a | 2 | #include "MMA7660.h" |
niallmoyvane | 0:7cd973be7a0a | 3 | |
niallmoyvane | 0:7cd973be7a0a | 4 | Serial pc(USBTX,USBRX); |
niallmoyvane | 0:7cd973be7a0a | 5 | MMA7660 MMA(p28, p27); |
niallmoyvane | 0:7cd973be7a0a | 6 | |
niallmoyvane | 0:7cd973be7a0a | 7 | |
niallmoyvane | 0:7cd973be7a0a | 8 | float calculateAngle(float x, float y, float z) |
niallmoyvane | 0:7cd973be7a0a | 9 | { |
niallmoyvane | 0:7cd973be7a0a | 10 | float angle = 0; |
niallmoyvane | 0:7cd973be7a0a | 11 | angle= (atan(x/sqrt((y*y)+(z*z))))*180.0/ 3.14159265; |
niallmoyvane | 0:7cd973be7a0a | 12 | return angle; |
niallmoyvane | 0:7cd973be7a0a | 13 | |
niallmoyvane | 0:7cd973be7a0a | 14 | } |
niallmoyvane | 0:7cd973be7a0a | 15 | int main() |
niallmoyvane | 0:7cd973be7a0a | 16 | { |
niallmoyvane | 0:7cd973be7a0a | 17 | while (1) |
niallmoyvane | 0:7cd973be7a0a | 18 | { |
niallmoyvane | 0:7cd973be7a0a | 19 | pc.printf("x%f, y%f, z%f, ang%f\n\r",MMA.x(),MMA.y(),MMA.z(),calculateAngle(MMA.x(),MMA.y(),MMA.z())); |
niallmoyvane | 0:7cd973be7a0a | 20 | wait(1); |
niallmoyvane | 0:7cd973be7a0a | 21 | } |
niallmoyvane | 0:7cd973be7a0a | 22 | } |
niallmoyvane | 0:7cd973be7a0a | 23 |