Hi Guys, thanks for all the awesome help-sorry it's taken me so long to reply-been too busy to get back to the project until now. Here is where I'm at (confused), below:
I am confused as to what this does?
int val1=a;
int val2=c;
**Also, not sure how to set these? Do these represent the distance traveled? **
|| int fromTarget1 - a variable containing the minimum servo 1 position
|| int toTarget1 - a variable containing maximum servo 1 position
|| int fromTarget2 - a variable containing the minimum servo 2 position
|| int toTarget2 - a variable containing maximum servo 2 position
randomSeed(millis());
// Choose Point A
randomXR=random(50,100); //creates random X position
randomYR=random(50,200); //creates random Y position
//creates an random position area to move servos around, based on preset XY position
randomxa=random((panVal-randomXR),(panVal+randomXR));
randomya=random((tiltVal-randomYR),(tiltVal+randomYR));
//Move Servo XY positions to A
servo1.write(randomxa);
servo2.write(randomya);
// Set delay between next move
randomDice=random(8); //sets a random longer delay to happen, if diceroll is 3
Serial.println(randomDice);
if (randomDice == 3){
randomDelay2 = random(1000);
}
else {
randomDelay2 = 0;
}
//random HOLD delay function, add even more randomness for intervals of slow/fast movement
randomDelay1 = random(250,500); //pick a random number for delay
delay(randomDelay1 + randomDelay2); //normal delay plus diceroll random of much longer delay
// Choose Point B
Serial.println(" forward ");
randomXR=random(50,100); //creates random X position
randomYR=random(50,200); //creates random Y position
randomxb=random((panVal-randomXR),(panVal+randomXR));
randomyb=random((tiltVal-randomYR),(tiltVal+randomYR));
//GIVEN:
** int from1=randomxa;**
** int to1=randomxb;**
** int from2=randomya;**
** int to2=randomyb;**
** int val1=a;**
** int val2=c;**
/*
|| int& from1 - the adress of the variable that contains current pos for servo 1
|| int& from2 - the adress of the variable that contains current pos for servo 2
|| int fromTarget1 - a variable containing the minimum servo 1 position
|| int toTarget1 - a variable containing maximum servo 1 position
|| int fromTarget2 - a variable containing the minimum servo 2 position
|| int toTarget2 - a variable containing maximum servo 2 position
*/
** // 400-300 = 100**
** int diff1 = toTarget1 - fromTarget1**
** // 200 - 700 = -500**
** int diff2 = toTarget2 - fromTarget2;**
** // 100 / -500 = -0.2**
** int rel1 = diff1 / diff2;**
** // -500 / 100 = -5**
** int rel2 = diff2 / diff1;**
** //this sets rel1 to 1**
** if(rel1<1&&rel1>=0){rel1=1;}**
** //evaluates false**
** if(rel2<1&&rel2>=0){rel2=1;}**
** //original servo 1 pos increases with 1**
** // this syntax is equal to:**
** // from1 = from1 + rel;**
** from1+= rel1;**
** //original servo 2 pos increases with -5**
** from2+= rel2;**
// SETS DELAY UNTIL IT LOOPS BACK to A
randomDice=random(8); //sets a random longer delay to happen, if diceroll is 3
Serial.println(randomDice);
if (randomDice == 3){
randomDelay2 = random(1000);
}
else {
randomDelay2 = 0;
}
//random HOLD delay function
randomDelay1 = random(250,500); //pick a random number for delay
delay(randomDelay1 + randomDelay2); //normal delay plus diceroll random of much longer delay