Advertisement
Guest User

Untitled

a guest
May 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. void test_accelerometer_module(void) {
  2.  
  3. // Display the acclerometer on the LCD
  4. int k = 0;
  5. int count = 0;
  6. long int sum = 0;
  7. long int average;
  8.  
  9. setStrings("Tilt", "");
  10.  
  11.  
  12. // Loop to constantly display acceleration
  13. for (;;){
  14.  
  15. obtainAccelData(axraw, ayraw, azraw); // Get the raw acceleration data
  16. k = accelToDegrees(axraw, azraw); // Read in the index which corresponds to the degree
  17. //average = k; // intially display the accel
  18.  
  19. // Perform the average over 200 samples
  20. sum = sum+k; // Add the current degree to the cumulative sum
  21.  
  22. if (count == 199){ // Wait to take the sample of 200 values
  23. average = sum/200; // Calculate the average of these samples
  24. lcdTop1DP(average); // Display the accel pretty
  25. count = 0; // Reset the count, sum and average
  26. sum = 0;
  27. average = 0;
  28. }
  29. else { // If 200 samples haven't been taken, increment the count
  30. count = count+1;
  31. }
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. //dispTop(k);
  39. //dispTop(*azraw); // Displays the x acceleration data
  40. //setSevenSegDec(*axraw); // For now, display also on 7 seg
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement