Posted By

parkerkrhoyt on 11/04/11


Tagged

data rotation record capture Sensor device tilt mark accelerometer


Versions (?)

Capturing Relative Accelerometer Tilt


 / Published in: JavaScript
 

  1. function sample()
  2. {
  3. vmax = latest.x + 0.25;
  4. vmin = latest.x - 0.25;
  5. vrange = 0.50;
  6.  
  7. hmax = latest.y + 0.25;
  8. hmin = latest.y - 0.25;
  9. hrange = 0.50;
  10. }
  11.  
  12. function move()
  13. {
  14. var hposition = 0;
  15. var vposition = 0;
  16.  
  17. vposition = ( ( ( latest.x - vmin ) / vrange ) * BRICKS_SPACE ) + BRICKS_MAXIMUM;
  18. hposition = ( ( latest.y - hmin ) / hrange ) * LEGS_SPACE;
  19.  
  20. // Keep in bounds
  21. if( vposition > BRICKS_MAXIMUM )
  22. {
  23. vposition = BRICKS_MAXIMUM;
  24. } else if( vposition < BRICKS_MINIMUM ) {
  25. vposition = BRICKS_MINIMUM;
  26. }
  27.  
  28. if( hposition < LEGS_MINIMUM )
  29. {
  30. hposition = LEGS_MINIMUM;
  31. } else if( hposition > LEGS_MAXIMUM ) {
  32. hposition = LEGS_MAXIMUM;
  33. }
  34.  
  35. $( '#background' ).css( 'top', vposition );
  36. $( '#legs' ).css( 'left', hposition );
  37. }

Report this snippet  

You need to login to post a comment.