Hello everyone,
Currently I am working a project..I have 8x8 piezoresistive sensor matrix (i simply used 2 muxs) and I have only 1 analog output that gives me 64 different voltage values (changes depending on the pressure,and its between 2.5 V -5V) for each scan..so what i want to do is,to scan the matrix 10 times and get the averaged values of each cell of the matrix called smoothing..I do know how to do it for single readings but as i mentioned above I get 64 values..so somehow for each loop i have to store 64 values each time and smooth the data..Here what I have wrote..
const int numReadings = 64; // Number of readings for each scan
const int numLoop=10; //Number of loops for each scan
float readings[numReadings]; // the readings from the analog input after each scan
float totReadings[numLoop]; //total readings from the analog input scan
int index_readings = 0; // the index of the current reading
int index_loop=0; // the index of the current loop
float average[numReadings]; //Averaged value
int total[numReadings][numLoop];
int inputPin = A0; //Determine the pin
void setup()
{
Serial.begin(9600);
// initialize all the readings
for (int i = 0; i < numReadings; i++)
readings[i] = 0;
// initialize all the loops
for(int j=0; j<numLoop;j++)
totReadings[j]=0;
}
void loop() {
// read from the sensor:
totReadings[numLoop]=totReadings[numLoop]+readings[index_readings];
readings[index_readings] = analogRead(inputPin); //Read the data from sensor (64 values)
// advance to the next position in the array:
index_readings = index_readings + 1;
index_loop = index_loop + 1;
// if we're at the end of the array...
if (index_readings >= numReadings)
// ...wrap around to the beginning:
index_readings = 0;
if (index_loop >= numLoop)
// ...wrap around to the beginning:
index_loop = 0;
//Take the average value
average[numReadings]=totReadings[numLoop]/numLoop; //Averaged value divided by 10(number of loops)
Serial.println(average[numReadings]); //Print the averaged value 64x1
delay(100);
}
}
}
I havent tested it yet but I do not feel satisfied though..I would be grateful to you if you can give me some ideas for improvement..Thanks a lot in advance..
