Hi.

I'm trying to get output 1 and output 2 to go low and high independently.
What I'm trying to do;

Output 1 should control a light (through a relay module) that turns on for 14 hours and off for 10.
Output 2 should control a pump (through a relay module) thats supposed to be off for several days then on for 20 seconds or so, then repeat.

I've read a lot of examples but all seems quite advanced. Is it an easy way to do this?
I read about the scheduler library, but I don't have a Due, Zero or MKR1000, just got an Uno r3.
But can't seem to figure out how to "transfer" this to my project.

consider the following

``````#define Period1     50
#define Period2    100
#define Period3    150

int           ang   = 0;
int           dAng  = 1;

int           st1   = 0;
int           dist  = 0;

unsigned long msec1 = 0;
unsigned long msec2 = 0;
unsigned long msec3 = 0;

void loop () {

unsigned long msec = millis();

// ----------------------------------------
// period 1 actions
if (msec - msec1 > Period1) {
msec1 = msec;

ang += dAng;
myservo.write (ang);

if (0 < dAng && 180 <= ang)
dAng = -dAng;
else if (0 > dAng && 0 >= ang)
dAng = -dAng;
}

// ----------------------------------------
// period 2 actions
if (msec - msec2 > Period2) {
msec2 = msec;

// state1 action
if (st1)
digitalWrite (LED, HIGH);

else                // state2 action
digitalWrite (LED, LOW);

st1 = ! st1;      // toggle state
}

// ----------------------------------------
if (msec - msec3 > Period3) {
msec3 = msec;

// period 3 actions
Serial.print   ("Distance: ");
Serial.println (dist);
}

// ----------------------------------------
// do something that doesn't need to wait

lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
}
``````

This will allow you to control 4 outputs each with separate on and off periods

``````const byte ledPins[] = {3,5,6,9};
const byte NUMBER_OF_LEDS = sizeof(ledPins);
unsigned long startTimes[NUMBER_OF_LEDS] = {};
byte indexes[NUMBER_OF_LEDS] = {0};
const byte MAX_NUMBER_OF_PERIODS = 10;
unsigned long periods[][MAX_NUMBER_OF_PERIODS] =    //periods for each LED.  zero indicates end of sequence
{
{1000, 2000, 1500, 2500, 0},
{500, 200, 1000, 2000, 3000, 4000, 0},
{400, 1000, 1500, 2000, 0},
{1100, 2200, 0}
};

void setup()
{
Serial.begin(115200);
for (int led = 0; led < NUMBER_OF_LEDS; led++)
{
pinMode(ledPins[led], OUTPUT);
}
}

void loop()
{
unsigned long currentTime = millis();
for (int led = 0; led < NUMBER_OF_LEDS; led++)  //iterate through the LEDs
{
if (currentTime - startTimes[led] >= periods[led][indexes[led]])  //? time to change ?
{
startTimes[led] = currentTime;  //save start time of state
indexes[led]++;                    //increment index
}
if (periods[led][indexes[led]] == 0)  //if next period is zero (end of sequence)
{
indexes[led] = 0;        //reset period index for this LED
}
}  //end for loop
}
``````

It is easily adjusted to use only 2 outputs and longer periods

See this example: Blink multiple LED without delay