Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. void Task_Motion_Sensor(void) {
  2.     static int16_t prev_acc_X=0, prev_acc_Y=0, prev_acc_Z=0;
  3.     int16_t acc_X=0, acc_Y=0, acc_Z=0;
  4.     uint8_t rf, gf, bf;
  5.    
  6.     SET_BIT(DEBUG_TASK_MOTION_SENSOR);          //  set task motion sensor bit high
  7.  
  8.     read_full_xyz(&acc_X, &acc_Y, &acc_Z);
  9.  
  10.     rf = abs(prev_acc_X - acc_X) > ACC_SENSITIVITY ? 1 : 0;
  11.     gf = abs(prev_acc_Y - acc_Y) > ACC_SENSITIVITY ? 1 : 0;
  12.     bf = abs(prev_acc_Z - acc_Z) > ACC_SENSITIVITY ? 1 : 0;
  13.  
  14.     Control_RGB_LEDs(rf, gf, bf);
  15.     Delay(FLASH_DELAY);
  16.     Control_RGB_LEDs(0, 0, 0);                         
  17.     Delay(FLASH_DELAY*2);      
  18.  
  19.     prev_acc_X = acc_X;
  20.     prev_acc_Y = acc_Y;
  21.     prev_acc_Z = acc_Z;
  22.     CLEAR_BIT(DEBUG_TASK_MOTION_SENSOR);        //  set task motion sensor bit low
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement