I built a robotic hand as shown at GitHub - pollen-robotics/AmazingHand: Code and model to control the AH!
I use Arduino Mega to control the robotic hand. I may have made a mistake when writing the code.
When I enter a number to close the fingers, the fingers should close and don’t open. How can I fix the problem?
#include <SCServo.h>
SCSCL sc;
int ID_1 = 11;
int ID_2 = 12;
int ID_3 = 13;
int ID_4 = 14;
int ID_5 = 15;
int ID_6 = 16;
int ID_7 = 17;
int ID_8 = 18;
int MiddlePos_1 = 511;
int MiddlePos_2 = 511;
int MiddlePos_3 = 511;
int MiddlePos_4 = 511;
int MiddlePos_5 = 511;
int MiddlePos_6 = 511;
int MiddlePos_7 = 511;
int MiddlePos_8 = 511;
void setup() {
Serial1.begin(1000000);
sc.pSerial = &Serial1;
delay(500);
Serial.begin(9600);
Serial.println();
Serial.println("1. Finger1 Open");
Serial.println("2. Finger1 Close");
Serial.println("3. Finger2 Open");
Serial.println("4. Finger2 Close");
Serial.println("5. Finger3 Open");
Serial.println("6. Finger3 Close");
Serial.println("7. Finger4 Open");
Serial.println("8. Finger4 Close");
Serial.println("9. All Fingers Open");
Serial.println("0. All Fingers Close");
}
void loop() {
int menuChoice = Serial.parseInt();
Serial.println("Which Finger do you want to open or close? ");
switch (menuChoice) {
case 0:
Serial.println("All Fingers are open ");
sc.RegWritePos(ID_1, MiddlePos_1-300, 0, 500); //Servo 1
sc.RegWritePos(ID_2, MiddlePos_2+300, 0, 500); //Servo 2
sc.RegWritePos(ID_3, MiddlePos_3-300, 0, 500); //Servo 1
sc.RegWritePos(ID_4, MiddlePos_4+300, 0, 500); //Servo 2
sc.RegWritePos(ID_5, MiddlePos_5-300, 0, 500); //Servo 1
sc.RegWritePos(ID_6, MiddlePos_6+300, 0, 500); //Servo 2
sc.RegWritePos(ID_7, MiddlePos_7-300, 0, 500); //Servo 1
sc.RegWritePos(ID_8, MiddlePos_8+300, 0, 500); //Servo 2
sc.RegWriteAction();
delay(500);
break;
case 1:
Serial.println("All Fingers are closed ");
sc.RegWritePos(ID_1, MiddlePos_1+300, 0, 500); //Servo 1
sc.RegWritePos(ID_2, MiddlePos_2-300, 0, 500); //Servo 2
sc.RegWritePos(ID_3, MiddlePos_3+300, 0, 500); //Servo 1
sc.RegWritePos(ID_4, MiddlePos_4-300, 0, 500); //Servo 2
sc.RegWritePos(ID_5, MiddlePos_5+300, 0, 500); //Servo 1
sc.RegWritePos(ID_6, MiddlePos_6-300, 0, 500); //Servo 2
sc.RegWritePos(ID_7, MiddlePos_7+300, 0, 500); //Servo 1
sc.RegWritePos(ID_8, MiddlePos_8-300, 0, 500); //Servo 2
sc.RegWriteAction();
delay(500);
break;
case 2:
Serial.println("Finger1 is open ");
sc.RegWritePos(ID_1, MiddlePos_1-300, 0, 500); //Servo 1
sc.RegWritePos(ID_2, MiddlePos_2+300, 0, 500); //Servo 2
sc.RegWriteAction();
delay(500);
break;
case 3:
Serial.println("Finger1 is closed ");
sc.RegWritePos(ID_1, MiddlePos_1+300, 0, 500); //Servo 1
sc.RegWritePos(ID_2, MiddlePos_2-300, 0, 500); //Servo 2
sc.RegWriteAction();
delay(500);
break;
case 4:
Serial.println("Finger2 is open ");
sc.RegWritePos(ID_3, MiddlePos_3-300, 0, 500); //Servo 1
sc.RegWritePos(ID_4, MiddlePos_4+300, 0, 500); //Servo 2
sc.RegWriteAction();
delay(500);
break;
case 5:
Serial.println("Finger2 is closed ");
sc.RegWritePos(ID_3, MiddlePos_3+300, 0, 500); //Servo 1
sc.RegWritePos(ID_4, MiddlePos_4-300, 0, 500); //Servo 2
sc.RegWriteAction();
delay(500);
break;
case 6:
Serial.println("Finger3 is open ");
sc.RegWritePos(ID_5, MiddlePos_5-300, 0, 500); //Servo 1
sc.RegWritePos(ID_6, MiddlePos_6+300, 0, 500); //Servo 2
sc.RegWriteAction();
delay(500);
break;
case 7:
Serial.println("Finger3 is closed ");
sc.RegWritePos(ID_5, MiddlePos_5+300, 0, 500); //Servo 1
sc.RegWritePos(ID_6, MiddlePos_6-300, 0, 500); //Servo 2
sc.RegWriteAction();
delay(500);
break;
case 8:
Serial.println("Finger4 is open ");
sc.RegWritePos(ID_7, MiddlePos_7-300, 0, 500); //Servo 1
sc.RegWritePos(ID_8, MiddlePos_8+300, 0, 500); //Servo 2
sc.RegWriteAction();
delay(500);
break;
case 9:
Serial.println("Finger4 is closed ");
sc.RegWritePos(ID_7, MiddlePos_7+300, 0, 500); //Servo 1
sc.RegWritePos(ID_8, MiddlePos_8-300, 0, 500); //Servo 2
sc.RegWriteAction();
delay(500);
break;
//default:
// Serial.println("Please choose a valid selection");
}
}