Run two Loops Simultaneously on Arduino I am not able to combine the below two sketches. What I require is to either run both the loops together or find a way to run both the functions inside a single loop.

Sketch 1

#include &lt;SevSeg.h&gt;
#include &lt;DS1307RTC.h&gt;
#include &lt;Time.h&gt;
#include &lt;TimeLib.h&gt;
#include &lt;Wire.h&gt;

// Create an instance of the object
SevSeg sevseg;
bool militaryTime = false; // true for 24 hour clock

void setup() {
  byte numDigits = 4;
  byte digitPins[] = {2, 3, 4, 5};
  byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
  bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_ANODE; // See README.md for options
  bool updateWithDelays = false; // Default. Recommended
  bool leadingZeros = true; // Use 'true' if you'd like to keep the leading zeros

  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros);
  sevseg.setBrightness(90);
}

void loop() {
  tmElements_t tm;
  int time;
  int dot;

  if (RTC.read(tm)) {
    time = tm.Hour * 100;
    if (time &gt; 1200 &amp;&amp; militaryTime == false) {
      time = time - 1200;
    }
    if (time == 0 &amp;&amp; militaryTime == false) {
      time = 1200;
    }
    time += tm.Minute;
  }

  if ((tm.Second % 2) == 0) {
    dot = 4;
  } else {
    dot = 2;
  }

  //Produce an output on the display
  sevseg.refreshDisplay();
  sevseg.setNumber(time, dot);
}


Sketch 2

// Change this to the output pin you are using
#define TICK_PIN A0

void setup()
{
  pinMode(TICK_PIN,OUTPUT);
  while (1) {
    tone(TICK_PIN,1000,2);
    delay(1000);
  }
}

void loop()
{
}
Basically you need to get rid of the delay and any other blocking loops. Here is a way to do it.

Define this variable globally.

unsigned long lastTime = 0;


Then in your first loop, add the following code either to the beginning or the end:

if (millis() - lastTime &gt;= 1000 || !lastTime) {
    lastTime = millis();
    tone(TICK_PIN,1000,2);
}