Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int fin;
- const int input[5] = {A0,A1,A2,A3,A4}; // the analog pins
- int flex[5]; // analog signal read
- float flexV;
- float flexR[5]; // resistance on the 47k resistor
- int angle[5]; // joint angles
- const float VCC = 4.98; // Measured voltage of Arduino 5V line
- // Measured resistance of the 47k resistors R1-R5
- const float R[5] = {45900.0,45900.0,45900.0,45900.0,45900.0};
- // Calibration values of resistance measured during straight phase and 90 deg bend phase
- const float R_STRAIGHT[5] = {37651.0,37651.0,37651.0,37651.0,37651.0};
- const float R_BEND[5] = {71783.0,71783.0,71783.0,71783.0,71783.0};
- void setup() {
- }
- void loop() {
- for(fin = 0; fin <= 4; fin++) {
- flex[fin] = analogRead(input[fin]);
- flexV = flex[fin]*VCC/1023.0;
- flexR[fin] = R[fin] * (VCC/flexV - 1.0);
- angle[fin] = map(flexR[fin],R_STRAIGHT[fin],R_BEND[fin],0,90.0);
- delay(1);
- }
- Serial.print(angle[0]);
- Serial.print(" ");
- Serial.print(angle[1]);
- Serial.print(" ");
- Serial.print(angle[2]);
- Serial.print(" ");
- Serial.print(angle[3]);
- Serial.print(" ");
- Serial.print(angle[4]);
- Serial.print(" ");
- Serial.println(millis());
- delay(6);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement