Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Test 2125 Tilt.c
- Version 0.94 for use with SimpleIDE 9.40 and its Simple Libraries
- Measure tilt. Assumes MX2125 is being held horizontally and then tilted.
- learn.parallax.com/propeller-c-simple-devices/tilt-and-acceleration-mx2125
- */
- #include "simpletools.h" // Include simpletools header
- #include "mx2125.h" // Include mx2125 header
- int main() // main function
- {
- while(1) // Repeat indefinitely
- {
- int x = mx_tilt(10); // X-axis tilt
- int y = mx_tilt(11); // Y-axis tilt
- print("%ctilt x = %d, tilt y = %d, %c\n", // Display tilts
- HOME, x, y, CLREOL);
- if (x > 5)
- {
- high(0);
- pause(500);
- }
- else if (x < -5)
- {
- high(1);
- pause(500);
- }
- else
- {
- low(0);
- low(1);
- }
- if (y > 5)
- {
- high(2);
- pause(500);
- }
- else if (y < -5)
- {
- high(3);
- pause(500);
- }
- else
- {
- low(2);
- low(3);
- }
- if ((x < -5) && (y < -5))
- {
- high(4);
- pause(500);
- }
- else if ((x < -5) && (y > 5))
- {
- high(5);
- pause(500);
- }
- else
- {
- low(4);
- low(5);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement