You are on page 1of 2

CALIBRATION

int fingerPins[5]={A0, A1, A2, A3, A4}; //order of finger connections from thumb to pinky respectively
int fingerVals[5]; //stores values of flex sensor on each finger
const char *names[5]={"Thumb: ", "Index: ", "Middle: ", "Ring: ", "Pinky: "};
int CalibrationVals[2][5];
void setup() {
Serial.begin(9600); .
CalibrateFlexSensors();
}
void loop() {
}
void CalibrateFlexSensors(){
int calibrationCount=0;
while(calibrationCount<=1){
if(calibrationCount==0){
Serial.println("Please lay your hand flat");
delay(3000);
Serial.println("Collecting minimum flex readings");
}
else if(calibrationCount==1){
Serial.println("Please close you hand into a fist");
delay(3000);
Serial.println("Collecting maximum flex readings");
}
for(int i=0; i<5; i++){
int readingCount=0;
int readingSum=0;
while(readingCount<10){ //Take 10 unique readings
readingSum+=analogRead(fingerPins[i]);
readingCount+=1;
delay(200);
}
CalibrationVals[calibrationCount][i]=readingSum/10; //Record average of 10 readings
}
calibrationCount+=1;
}
Serial.println("Calibration Complete");
Serial.println("In the order from thumb to pinky, your offsets are:");
for(int i=0; i<2; i++){
if(i==0){Serial.print("Minimum Offsets:\t");}
else{Serial.print("Maximum Offsets:\t");}
for(int j=0; j<5; j++){
Serial.print(CalibrationVals[i][j]);
Serial.print(", ");
}
Serial.println();
}
}
GENERAL
int val;
int flexPins[] = {A0, A1, A2, A3, A4};
int flexsensorRange[2][5] = {{155, 106, 148, 162, 123}, //maximum offset values from calibration
{77, 55, 74, 77, 73} //minimum offset values from calibration
};
void setup() {
Serial.begin(9600);
}
void loop() {
for (int i = 0; i < 5; i += 1) { //repeat process for each of the 5 fingers
val = analogRead(flexPins[i]); //reads the position of the finger
angles[i] = map(val, flexsensorRange[0][i], flexsensorRange[1][i], 0, 180);
//print an if/else statment to facilitate
angles[i] = constrain(angles[i], 0, 180); //any values above/below the maximum/minimum calibration
value are reset to the highest/lowest value within the acceptable range
Serial.print(angles[i]);
Serial.print('\t');
}
delay(500); //outputs readings in half-second intervals
}

You might also like