a regular routine using some form of timing

I have some complex code (attached) I am using to power a model submarine. What I want is some code that will run a one second routine, every ten seconds that I can fit into this.

I have looked at SimpleTimer however although I can see how it prints regularly and I can see how to how to vary that period, I don’t know where to put the code that will fire a routine. (trigger a relay)

Is there some code I can add which, when triggered, will cause a relay to fire for one second every ten?

This is not the finished product of course…

#include <SimpleTimer.h>

// the timer object
SimpleTimer timer;

// a function to be executed periodically
void repeatMe() {
    Serial.print("Uptime (s): ");
    Serial.println(millis() / 1000);
}

void setup() {
    Serial.begin(9600);
    timer.setInterval(1000, repeatMe);
}

void loop() {
    timer.run();
}

subsketchlatest8.ino (16.7 KB)

const int RelayPin = 7;
const unsigned long StartInterval = 10000;
const unsigned long OnInterval = 1000;
boolean RelayIsOn = false;
unsigned long LastStartTime = 0;
unsigned long LastOnTime = 0;

void setup() {
  pinMode(RelayPin, OUTPUT);
}

void loop() {
  if (RelayIsOn) {
    if (millis() - LastOnTime > OnInterval) {
      RelayIsOn = false;
      digitalWrite(RelayPin, LOW);
    }
  } 
  else {  // Relay is off
    if (millis() - LastStartTime > StartInterval) {
      RelayIsOn = true;
      LastOnTime = millis();
      digitalWrite(RelayPin, HIGH);
      LastStartTime = millis();
    }
  }
}
// ************* FUNCTION ModeDelay ****************
// Non-Blocking Delay, returns 1 when timed out
unsigned char ModeDelay(unsigned long dly)
  {
  static unsigned long ModeDelayCount;  
  static unsigned char ModeDelayInit = LOW;
  static unsigned char ModeDelayTimeout = LOW;

  if (ModeDelayInit == LOW)
    { // Run Once Code
    ModeDelayTimeout = LOW;            // Reset Flag
    ModeDelayCount = millis ();        // Snapshot of MILLIS count
    ModeDelayInit = HIGH;
    }

  if (((millis ()) - ModeDelayCount) >= dly)
    {
    ModeDelayTimeout = HIGH;              // set Flag
    ModeDelayInit = LOW;
    }
  return ModeDelayTimeout;
  }//------------------------------------------------------

I used type char b/c boolean or byte can't be declared in the .H file. If you call the function before it's done, nothing happens.

Hey guys thank you so much. SORTED!