Hello!
Please help me as im not very good in programming and I want to make a code to control a robotic arm through a joystick. I have tried to make a code in which each joint is assigned to a letter. To select the type of joint that I want to control, through the x-axis I look for the letter to move. Once found, to be able to select it, I have to press the joystick with the z-axis, and in this way I can move freely the joint without changing the letters assigned to the other joints. To select another letter, press the z-axis again and select the next letter with the x-axis. This is the code.
Any suggestions would be great!
Thank you
//Initialize Data Structures char alphabet[] = {' ','a','d','e','f','g','h','q','r','s','t','w','y'}; char text[50] = {'-', '-', '>'}; //Initialize Counters int alphabetCounter = 0; int textCounter = 3;
//Initialize Sensor Values int sensorValueX; int sensorValueY; int sensorValueZ;
// Define angle limits float minrot0 = -360, maxrot0 = 360; float minrot1 = 30, maxrot1 = 90; float minrot2 = -120, maxrot2 = -60; float minrot3 = -360, maxrot3 = 360; float minrot4 = -60, maxrot4 = 60;
void setup() {
// initialize serial communication at 9600 bits per second: Serial.begin(9600); Serial.print(text); Serial.println(alphabet[alphabetCounter]);
}
void loop() { sensorValueX = analogRead(A0); sensorValueY = analogRead(A1); sensorValueZ = analogRead(A2); if (sensorValueX > 750 || sensorValueX < 150 || sensorValueY > 750 || sensorValueY < 150 || sensorValueZ <10){
//// X-Axis Incriment and Decriment// if (sensorValueX > 750){// alphabetCounter++;// delay(500);// }// if (sensorValueX < 150){// alphabetCounter--;// delay(500);// }
// Y-Axis Incriment and Decriment if (sensorValueY > 750){ alphabetCounter++; delay(500); } if (sensorValueY < 150){ alphabetCounter--; delay(500); }
// Z-Axis Select Character if (sensorValueZ < 10){ delay(500); }
Serial.print(text); Serial.println(alphabet[alphabetCounter]);// Serial.println(alphabetCounter);// Serial.println(textCounter); }
}