Precise blink timing.

Hi, I am new to Arduino and would appreciate a bit of help regarding some basic theory.

I am trying to implement some code that will blink (fade) four LEDs. LEDs 1-3 blink every 1000, 900 and 800 ms respectively. This means that every 36000 ms all 3 LEDs are in sync, when this happens a 4th LED lights up.

I have implemented this using a modulated cos function. LEDs 1-3 are fairly straight forward, I just set the cos functions on their way and they work OK. The 4th LED is implemented rather crudely using a long period cos function for the timing and one of the shorter period functions for the actual fade.

Please can someone confirm whether my thinking is correct on the following points.
• As I have 4 things going on I can’t use the Delay() function.
• I can’t use the approach in the example sketch ‘BlinkwithoutDelay’. The ‘if(currentMillis - previousMillis >= interval)’ bit of that code means that actually its on and then off for APPROXIMATELY the interval time. I assume that over time this will drift and I will no longer have the syncing I am looking for.

What I have works, so I guess the real question I am asking is am I over complicating things? Is there a simpler way?

// V3 This works well. 3 pins beat independently with a 'big' beat every 36 seconds.

int value1, value2, value3, value4; 
int ledpin1 = 9;                           // light connected to digital pin 9
int ledpin2 = 10;                           // light connected to digital pin 10
int ledpin3 = 11;                           // light connected to digital pin 11
int ledpin4 = 6;                           // light connected to digital pin 6

long time=0;

long periodA = 36000;
long period1 = 1000;
long period2 = 900;
long period3 = 800;


void setup() 
{ 
 // nothing for setup 
} 

void loop() 
{ 
 time = millis();
 
   value1 = 255*sqrt(sq(cos(time*(PI/period1))));
   value2 = 255*sqrt(sq(cos(time*(PI/period2))));
   value3 = 255*sqrt(sq(cos(time*(PI/period3))));
   
 if (255*sqrt(sq(cos(time*(PI/periodA))))>254.7572965)
   {
   value4 = 255*sqrt(sq(cos(time*(PI/period1))));
   }
 else
   {
   value4 = 1;
   }
 
 analogWrite(ledpin1, value1);           
 analogWrite(ledpin2, value2);           
 analogWrite(ledpin3, value3);            
 analogWrite(ledpin4, value4);            
}

Yes avoid delays.
No the blink without delay will work and will stay in sync if you do it correctly.