Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define avgSize 20
- int i = 0;
- int A0 = 1, A1 = 7;
- int avgCnt = 0;
- unsigned long time = 0;
- int xAvg, yAvg;
- int xAvgBuf[avgSize];
- int yAvgBuf[avgSize];
- int analogRead(int in)
- {
- return in;
- }
- void setup()
- {
- }
- void loop () {
- for(int i = 0; i < 100; i++)
- {
- yAvgBuf[avgCnt] = analogRead(A1);
- xAvgBuf[avgCnt] = analogRead(A0);
- if(avgCnt >= avgSize - 1){
- xAvg = 0;
- yAvg = 0;
- for(int i = 0; i < avgSize; i++)
- {
- xAvg += xAvgBuf[i];
- xAvgBuf[i] = 0;
- yAvg += yAvgBuf[i];
- yAvgBuf[i] = 0;
- }
- xAvg = xAvg / avgSize;
- yAvg = yAvg / avgSize;
- avgCnt = 0;
- printf("xAvg: %d\n", xAvg);
- printf("yAvg: %d\n", yAvg);
- }
- else
- {
- avgCnt++;
- //delay(50);
- }
- }
- }
- int main(void) {
- // your code goes here
- setup();
- loop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement