Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define avgSize 20
  4.  
  5. int i = 0;
  6. int A0 = 1, A1 = 7;
  7.  
  8. int avgCnt = 0;
  9. unsigned long time = 0;
  10. int xAvg, yAvg;
  11. int xAvgBuf[avgSize];
  12. int yAvgBuf[avgSize];
  13.  
  14. int analogRead(int in)
  15. {
  16.     return in;
  17. }
  18.  
  19. void setup()
  20. {
  21.    
  22. }
  23.  
  24. void loop () {
  25.     for(int i = 0; i < 100; i++)
  26.     {
  27.         yAvgBuf[avgCnt] = analogRead(A1);
  28.         xAvgBuf[avgCnt] = analogRead(A0);
  29.     if(avgCnt >= avgSize - 1){
  30.         xAvg = 0;
  31.         yAvg = 0;
  32.         for(int i = 0; i < avgSize; i++)
  33.         {
  34.             xAvg += xAvgBuf[i];
  35.             xAvgBuf[i] = 0;
  36.             yAvg += yAvgBuf[i];
  37.             yAvgBuf[i] = 0;
  38.         }
  39.         xAvg = xAvg / avgSize;
  40.         yAvg = yAvg / avgSize;
  41.         avgCnt = 0;
  42.         printf("xAvg: %d\n", xAvg);
  43.         printf("yAvg: %d\n", yAvg);
  44.     }
  45.    
  46.     else
  47.     {
  48.         avgCnt++;
  49.         //delay(50);
  50.     }
  51.     }
  52. }
  53.  
  54. int main(void) {
  55.     // your code goes here
  56.     setup();
  57.     loop();
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement