Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. /*
  2. Test 2125 Tilt.c
  3.  
  4. Version 0.94 for use with SimpleIDE 9.40 and its Simple Libraries
  5.  
  6. Measure tilt. Assumes MX2125 is being held horizontally and then tilted.
  7.  
  8. learn.parallax.com/propeller-c-simple-devices/tilt-and-acceleration-mx2125
  9. */
  10.  
  11. #include "simpletools.h" // Include simpletools header
  12. #include "mx2125.h" // Include mx2125 header
  13.  
  14. int main() // main function
  15. {
  16. while(1) // Repeat indefinitely
  17. {
  18. int x = mx_tilt(10); // X-axis tilt
  19. int y = mx_tilt(11); // Y-axis tilt
  20. print("%ctilt x = %d, tilt y = %d, %c\n", // Display tilts
  21. HOME, x, y, CLREOL);
  22.  
  23. if (x > 5)
  24. {
  25. high(0);
  26. pause(500);
  27. }
  28. else if (x < -5)
  29. {
  30. high(1);
  31. pause(500);
  32. }
  33. else
  34. {
  35. low(0);
  36. low(1);
  37. }
  38. if (y > 5)
  39. {
  40. high(2);
  41. pause(500);
  42. }
  43. else if (y < -5)
  44. {
  45. high(3);
  46. pause(500);
  47. }
  48. else
  49. {
  50. low(2);
  51. low(3);
  52. }
  53. if ((x < -5) && (y < -5))
  54. {
  55. high(4);
  56. pause(500);
  57. }
  58. else if ((x < -5) && (y > 5))
  59. {
  60. high(5);
  61. pause(500);
  62. }
  63. else
  64. {
  65. low(4);
  66. low(5);
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement