Assistance to tweak some code. Have a short vid of what I need

Hi

This code is nearly finished, but I need a little help. Pls see video

Sorry the code is so clumsy but I am new at this and this is the result of some weeks work.
The code for the relay operation which shows the lags and the little click on the return of the joystick is found beginning at line 416. This is the full joystick movement.

The trim tab code is at 448. I can live with the problems but it should be fixable if someone can maybe take a look at it. It is when the full joystick is on its way back that the relay momentarily triggers. As I say, for what this does it will be fine, but it would nice to clean it up.

Whatever fixes this will fix the others and I will happily apply any suggestions

The code for the 5 second adjustments when running the diveroutine is found at lines 314 to 340. I have applied this from code provided by johnwasser on this forum. (Thankyou!) I have added my adjusted code (also attached) and you can see how I have adapted it to work on the sub. The code works just fine on its own, but when added to the ‘whole’ the relays light dimly and will not trigger. These same relays trigger very well in the code above.

Once this is going I wouldn’t mind also asking for someone to review it. It is pretty clumsy code!

subsketchlatest10.ino (17.7 KB)

_10_SEC_TIME_adjust.ino (915 Bytes)

AMPS-N: Yes you had two sketch. could you explain what we need to check here.

Be simple in your words. Use code tag for above . expalin what problem you facing & what you being expected.

const int RelayPin = 6;  // will not be needed

// period for periodic adjustment of the piston
 unsigned long StartInterval; 
const unsigned long OnInterval = 1000;
boolean RelayIsOn = true;
unsigned long LastStartTime = 0;
unsigned long LastOnTime = 0;
static int depthkeeppistontrigger;

void setup() {
  pinMode(RelayPin, OUTPUT);  // not be needed
  Serial.begin(9600);
}

void loop() 


// periodic adjustment of the iston
// when in depth keeping mode
{
  if (RelayIsOn) {
    Serial.println("relay ON first if");
    
    if (millis() - LastOnTime > OnInterval) {
      RelayIsOn = false;
      depthkeeppistontrigger = 0;
    }
  } 
  else {  // Relay is off
  Serial.println("relay off first if");
  StartInterval=millis();
    if (StartInterval - LastStartTime > 4000) {
      RelayIsOn = true;
      LastOnTime = millis();
      depthkeeppistontrigger = 1;
      LastStartTime = millis();
    }
  }
  
  Serial.print("depthkeeppistontrigger:");
  Serial.println(depthkeeppistontrigger);
  
  if (depthkeeppistontrigger == 1){
    digitalWrite(RelayPin, LOW);
  }
  else {
    digitalWrite(RelayPin, HIGH);
  }
delay(1000);



}

Here i checked code . your relay will high for every 4s then goes off 1s.I could not able understand in detail. Might my english too poor i get you.

Check this part which is more confusing

Why you are trying to set PUMP_DIVE_PIN high & LOW both same condition

it does not make sense because @ intial stage it check unBallastIn>1600 so it set always PUMP_DIVE_PIN =Low
instead of HIGH

  if (unBallastIn > 1600)
  {

    if ( (millis () - PUMP_DIVE_PINtimer) >= PUMP_DIVE_PINinterval)
      digitalWrite(PUMP_DIVE_PIN, LOW);
  }
  else if (unBallastIn < 1600)
  {
    digitalWrite(PUMP_DIVE_PIN, HIGH);
    PUMP_DIVE_PINtimer = millis (); 
  }
  if (unBallastIn > 1700)
  {
    digitalWrite(PUMP_DIVE_PIN, HIGH);  

  }

If you can tell us which part of code you finding problem , mean you have doubt we can sort out.

The smaller sketch is what I 'tweaked' and then melded into subsketchlatest10 316 - 343. It works on its own nicely, but not in the larger sketch as per the video.

Please note the relays are triggered by LOW, not HIGH.

Hi all

Thanks for your help but I fixed it myself. Just needed to create another couple of integers to make the commands to the piston dive pin direct. All good now.