This issue has been resolved since the time of posting.
Error was in my variable declaration of CommandValues once i fixed this declaration the program executes how it should
Hey everyone,
I am having a little bit of an issue with a project I am working on.
I have 2 modified servos which work great I am using them in ALOT of my other projects fine. However I am comming across an issue where the servos will stop and not start back up again after a function call is made.
Here is my loop
servo1.write(180);
servo2.write(180);
byte data[14];
String test = "10020030040011"; //These 2 lines are to ommit code dealing with NRF24L01 comminucation
test.getBytes(data, 14); //and basically creates the same data it would receive without actually having the code to do so
ReadData(data); //The function that is causing all the mayhem!
servo1.write(0);
servo2.write(0);
Now if I comment out ReadData function then my servos will work exactly how I need them too.
When I uncomment ReadData function my servos will not work at all.
If I place a 20 second delay before ReadData the servos will move one way for 20 seconds, then stop and not move at all even when the loop is repeated
Here is the function causing all this mayhem
void ReadData(byte data[]){
char thedata[14];
ByteToChar(data,thedata,14);
String temp = (String(thedata[0]) + String(thedata[1]) + String(thedata[2])); //Grabs the first three characters and turn them into a String
CommandValues[0] = temp.toInt(); //convert that into an integer
if(CommandValues[0] >= 45 && CommandValues[0] <= 55){
CommandValues[0] = 50; //Used to level out wobly joystick
}
temp = (String(thedata[3]) + String(thedata[4]) + String(thedata[5])); //Grab the next three
CommandValues[1] = temp.toInt(); //To int
if(CommandValues[1] >= 45 && CommandValues[1] <= 55){
CommandValues[1] = 50;
}
temp = (String(thedata[6]) + String(thedata[7]) + String(thedata[8]));
CommandValues[2] = temp.toInt();
temp = (String(thedata[9]) + String(thedata[10]) + String(thedata[11]));
CommandValues[3] = temp.toInt();
temp = String(thedata[12]);
CommandValues[4] = temp.toInt();
temp = String(thedata[13]);
CommandValues[5] = temp.toInt();
return;
}
As you can see it basically converts the byte array into a character array and then builds the data into integer variables.
I am not sure what is wrong with the function but it is somehow interfering with the results I would expect from the execution of this program
Any ideas on what could be wrong with the function, ways it could be cleaned up or just some advice. I would love to hear it.
Thanks.
Andrew.