//pin 2 reserved for interrupt for hall sensor
const byte RELAY1=3; //linear actuator expand
const byte RELAY2=4; //linear actuator contract
const byte RELAY3=5; //rotary actuator clockwise
const byte RELAY4=6; //rotary actuator counter clockwise
const int actPot = A2; // actuator pot pin
const int brkPot = A3; // brake pot pin
Do you plan, at some point, to move the actuator and brake to other pins, such as maybe putting the actuator pot on analog pin 12478 and the brake pot on analog pin -25639?
int tgtValue = 0; //target value you want frame's linear actuator to be at
int tgt2Value = 0;//target value you want brake's rotary actuator to be at
Is it that difficult to use meaningful names? Why would I want to have to go back and look at the comments to see what the variable is used for? tgtActValue and tgtBrkValue mean that I don't need to.
tgt2Value=int (776.769 - (.5152 * actValue));
actValue=analogRead(actPot); //value of linear actuator's yo-yo pots 390 457 525 577 650 (-10 degree down to +10degree up)
So, the target brake value depends on the actuator value, so after we calculate the target, let's see what the actuator value IS Hmmm.
while(actValue < 300 && actValue > 750){Serial.print("TILT1");//if the values are out of bound the pot or something else broke
}
If something went wrong, there is no opportunity to correct the problem without resetting the Arduino. Is that what you really want? Perhaps there was simply an electrical spike causing an out-of-band reading. Take another reading, and everything might be OK.
That is NOT a good test for the potentiometer having become disconnected, as the comment implies.
if (diff1 <= 5 && diff1 >= -5) {
digitalWrite(RELAY3, HIGH);
digitalWrite(RELAY4, HIGH);
}
Do you really think that way? Personally, when checking that a value is in range, I check that it is above the low end first.
if (diff1 <= 5 && diff1 >= -5) {
digitalWrite(RELAY3, HIGH);
digitalWrite(RELAY4, HIGH);
}
if (diff1 >5 ) {
digitalWrite(RELAY3, LOW);
digitalWrite(RELAY4, HIGH);
}
if (diff1 <-5){
digitalWrite(RELAY3, HIGH);
digitalWrite(RELAY4, LOW);
}
How many of these if statements will evaluate to true on any given pass through loop()? When the answer is "never more than one", if/else if/else is more appropriate than if/if/if
while(brkValue < 350 && brkValue > 650){Serial.print("TILT2"); //if the pot is out of bounds the pot probably broke
}
While the number is less than 350 and greater than 650, do this. Just how many values, in the real world, satisfy that criteria?
There is nothing in your code to write to an LCD or to read from a hall effect sensor, so it is difficult to imagine what issues you are having using them.
I CAN imagine that all those delay()s are going to take a bite out of your posterior eventually. Make them go away now.