const int led = 11;
const int strain1Pin = A1;
const int strain2Pin = A2;
const int strain3Pin = A3;
const int strain4Pin = A4;
const int strain5Pin = A5;
const int strain6Pin = A6;
const int strain7Pin = A7;
const int strain8Pin = A8;
const int strain9Pin = A9;
int strain1;
int strain2;
int strain3;
int strain4;
int strain5;
int strain6;
int strain7;
int strain8;
int strain9;
float filterVal; // this determines smoothness - .0001 is max 1 is off (no smoothing)
float smoothedVal1; // this holds the last loop value
float smoothedVal2; // this will be necessary to apply low-pass filter to subsequent sensors.
float smoothedVal3;
float smoothedVal4;
float smoothedVal5;
float smoothedVal6;
float smoothedVal7;
float smoothedVal8;
float smoothedVal9;
//Serial.begin(9600);
pinMode(strain1Pin, INPUT);
pinMode(strain2Pin, INPUT);
pinMode(strain3Pin, INPUT);
pinMode(strain4Pin, INPUT);
pinMode(strain5Pin, INPUT);
pinMode(strain6Pin, INPUT);
pinMode(strain7Pin, INPUT);
pinMode(strain8Pin, INPUT);
pinMode(strain9Pin, INPUT);
pinMode(led, OUTPUT);
digitalWrite(led, HIGH); // did you want the led to do something?
filterVal = 0.75; //Low pass filter coefficient - applies to all inputs. Must = 0 to 1.
strain1 = analogRead(strain1Pin);
smoothedVal1 = smooth(strain1, filterVal, smoothedVal1);
strain2 = analogRead(strain2Pin);
smoothedVal2 = smooth(strain2, filterVal, smoothedVal2);
strain3 = analogRead(strain3Pin);
smoothedVal3 = smooth(strain3, filterVal, smoothedVal3);
strain4 = analogRead(strain4Pin);
smoothedVal4 = smooth(strain4, filterVal, smoothedVal4);
strain5 = analogRead(strain5Pin);
smoothedVal5 = smooth(strain5, filterVal, smoothedVal5);
strain6 = analogRead(strain6Pin);
smoothedVal6 = smooth(strain6, filterVal, smoothedVal6);
strain7 = analogRead(strain7Pin);
smoothedVal7 = smooth(strain7, filterVal, smoothedVal7);
strain8 = analogRead(strain8Pin);
smoothedVal8 = smooth(strain8, filterVal, smoothedVal8);
strain9 = analogRead(strain9Pin);
smoothedVal9 = smooth(strain9, filterVal, smoothedVal9);
Serial.print("Strain 1 value: ");
Serial.println(smoothedVal1);
Serial.print("Strain 2 value: ");
Serial.println(smoothedVal2);
Serial.print("Strain 3 value: ");
Serial.println(smoothedVal3);
Serial.print("Strain 4 value: ");
Serial.println(smoothedVal4);
Serial.print("Strain 5 value: ");
Serial.println(smoothedVal5);
Serial.print("Strain 6 value: ");
Serial.println(smoothedVal6);
Serial.print("Strain 7 value: ");
Serial.println(smoothedVal7);
Serial.print("Strain 8 value: ");
Serial.println(smoothedVal8);
Serial.print("Strain 9 value: ");
Serial.println(smoothedVal9);
usbMIDI.sendPitchBend(smoothedVal1, 1);
usbMIDI.sendPitchBend(smoothedVal2, 2);
usbMIDI.sendPitchBend(smoothedVal3, 3);
usbMIDI.sendPitchBend(smoothedVal4, 4);
usbMIDI.sendPitchBend(smoothedVal5, 5);
usbMIDI.sendPitchBend(smoothedVal6, 6);
usbMIDI.sendPitchBend(smoothedVal7, 7);
usbMIDI.sendPitchBend(smoothedVal8, 8);
usbMIDI.sendPitchBend(smoothedVal9, 9);
//usbMIDI.sendNoteOn(strain/10, 120, 1); // sends 1/10th of strain as ch 1 note. (debugging)
delay(50); // 20Hz refresh rate
int smooth(int data, float filterVal, float smoothedVal){
if (filterVal > 1){ // check to make sure param's are within range
filterVal = .99;
}
else if (filterVal <= 0){
filterVal = 0;
}
smoothedVal = (data * (1 - filterVal)) + (smoothedVal * filterVal);