I am doing a project where I am using 6 flex sensors to control servo motors in a prosthetic hand. I need to smooth the analog inputs with an array. I successfully was able to smooth one input but everytime I try to do multiple it just does not work. A launching point for this code would be super helpful. // Define the number of samples to keep track of. The higher the number, the
// more the readings will be smoothed, but the slower the output will respond to
// the input. Using a constant rather than a normal variable lets us use this
// value to determine the size of the readings array.
Below is a copy of the code as we currently have it. I keep getting int[int] errors in the piece directly after void loop.
const int numReadings = 50;
const int numChannels = 2;
int readings[numChannels][numReadings]; // the readings from the analog input
int index; // the index of the current reading
int total [numChannels]; // the running total
int average [numChannels];
// the running total
const int analogOutPin = 9;
const int analogOutPin1 = 10;
int inputPin = A0;
int inputPin1 = A1;
int sensorValue = 0; // value read from the pot
int outputValue = 0;
int sensorValue1 = 0;
int outputValue1 = 0;
void setup(){
// initialize serial communication with computer:
Serial.begin(9600);
}
void loop() {
for (int chan = 0; chan < numChannels; ++chan) {
total[chan] = total[chan] - readings[chan][index];
total[chan] += analogRead(inputPin [chan]);}
for (int chan = 1; chan < numChannels; ++chan) {
total[chan] = total[chan] - readings[chan][index];
total[chan] += analogRead(inputPin [chan]);}
// map it to the range of the analog out:
outputValue = map(average, 0, 630, 0, 255);
outputValue1 = map(average1, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
analogWrite(analogOutPin1, outputValue1);
// send it to the computer as ASCII digits
Serial.println(average);
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
Serial.println(average1);
Serial.print("sensor1 = ");
Serial.print(sensorValue1);
Serial.print("\t output1 = ");
Serial.println(outputValue1);
// change the analog out value:
delay(1); // delay in between reads for stability