Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. int fin;
  2. const int input[5] = {A0,A1,A2,A3,A4}; // the analog pins
  3.  
  4. int flex[5]; // analog signal read
  5. float flexV;
  6. float flexR[5]; // resistance on the 47k resistor
  7. int angle[5]; // joint angles
  8.  
  9. const float VCC = 4.98; // Measured voltage of Arduino 5V line
  10. // Measured resistance of the 47k resistors R1-R5
  11. const float R[5] = {45900.0,45900.0,45900.0,45900.0,45900.0};
  12.  
  13. // Calibration values of resistance measured during straight phase and 90 deg bend phase
  14. const float R_STRAIGHT[5] = {37651.0,37651.0,37651.0,37651.0,37651.0};
  15. const float R_BEND[5] = {71783.0,71783.0,71783.0,71783.0,71783.0};
  16.  
  17. void setup() {
  18.  
  19. }
  20.  
  21. void loop() {
  22.  
  23. for(fin = 0; fin <= 4; fin++) {
  24. flex[fin] = analogRead(input[fin]);
  25. flexV = flex[fin]*VCC/1023.0;
  26. flexR[fin] = R[fin] * (VCC/flexV - 1.0);
  27. angle[fin] = map(flexR[fin],R_STRAIGHT[fin],R_BEND[fin],0,90.0);
  28. delay(1);
  29. }
  30. Serial.print(angle[0]);
  31. Serial.print(" ");
  32. Serial.print(angle[1]);
  33. Serial.print(" ");
  34. Serial.print(angle[2]);
  35. Serial.print(" ");
  36. Serial.print(angle[3]);
  37. Serial.print(" ");
  38. Serial.print(angle[4]);
  39. Serial.print(" ");
  40. Serial.println(millis());
  41. delay(6);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement