Making accurate clock with no delay?

I'm making a clock with Mega2560.

It have to do these thing simultaneously.
-Displaying 128x64 graphic LCD.
-Sensing capacitive sensor.
-4-wire resistive touch panel.
-Sensing two different voltage values.
-Single button.
-RF receiver.
-Read from RTC sevral times.

Every other inputs except RTC should do some "interrupt" so that it can draw graphic LCD again. BUT with clocks ticking (from stopwatch to timer).

I made my code like

int tasks[10];
int now_task;

void loop()
{
now_task=0;
if(/Something happens/)
   tasks[now_task]=/specified code/; now_task++;

/few more similar if()/

for(int k=0 ; k<now_task ; k++)
{
switch(tasks[now_task])
{  case 1:
   /something/
   /tens of same cases/
}
}

Used no delay() function. Just used millis() function.
But the task itself is delaying the MCU.
This lowers the sampling rate of clock, and time is jumping.

I think I have to change algorithm for multitasking to solve this problem.
Any recommendations? Or..Just have to use due for faster processing?

P.S. I have external RTC too. It might help it anyway?
P.P.S. My mother tongue is not English. There may be lots of grammatical errors and awkwardness of expressions. Sorry for that and I beg your wide generosity.

One of the prominent members, CrossRoads, made this sketch for a millis()-based clock.
And accurate.
I modified it for 24-hour format.

/*  
    CrossRoads Timeclock  
    Adapted for 24hr time
    by Me!  08SEPT2012
    __h__m__s
    and leading zeros, too
*/
unsigned long previousTime = 0;
byte seconds ;
byte minutes ;
byte hours ;

void setup()
{
  //  Preset HHMMSS for 24hr rollover test
  //  Could jump to a function to set time
  //  and start
  seconds = 45;
  minutes =  59;
  hours =  23;
  Serial.begin (9600);
}

void loop ()
{
// I  think using microseconds is even more accurate
  if (millis() >= (previousTime)) 
  {
     previousTime = previousTime + 1000;  // use 100000 for uS
     seconds = seconds +1;
     if (seconds == 60)
     {
        seconds = 0;
        minutes = minutes +1;
     }
     if (minutes == 60)
     {
        minutes = 0;
        hours = hours +1;
     }
     if (hours == 24)
     {
       hours = 0;
     }
     if (hours < 10)
     {
       Serial.print("0");
     }
     Serial.print (hours, DEC);
     Serial.print ("h");
     if (minutes < 10)
     {
       Serial.print("0");
     }
     Serial.print (minutes,DEC);
     Serial.print ("m");
     if (seconds < 10)
     {
       Serial.print("0");
     }
     Serial.print(seconds,DEC);
     Serial.println("s");
  } // end 1 second
} // end loop

So, if your LCD routines can execute in the time it takes to do (and in place of) the Serial.print stuff then you'll be alright. (The LCD routine cannot use delay().)

ky9129:
I'm making a clock with Mega2560.

It have to do these thing simultaneously.
-Displaying 128x64 graphic LCD.
-Sensing capacitive sensor.
-4-wire resistive touch panel.
-Sensing two different voltage values.
-Single button.
-RF receiver.
-Read from RTC sevral times.

Every other inputs except RTC should do some "interrupt" so that it can draw graphic LCD again. BUT with clocks ticking (from stopwatch to timer).

I made my code like

int tasks[10];

int now_task;

void loop()
{
now_task=0;
if(/Something happens/)
   tasks[now_task]=/specified code/; now_task++;

/few more similar if()/

for(int k=0 ; k<now_task ; k++)
{
switch(tasks[now_task])
{  case 1:
   /something/
   /tens of same cases/
}
}




Used no delay() function. Just used millis() function.
But the task itself is delaying the MCU.
This lowers the sampling rate of clock, and time is jumping.

I think I have to change algorithm for multitasking to solve this problem. 
Any recommendations? Or..Just have to use due for faster processing?


P.S. I have external RTC too. It might help it anyway?
P.P.S. My mother tongue is not English. There may be lots of grammatical errors and awkwardness of expressions. Sorry for that and I beg your wide generosity.

The RTC is most accurate.

Nick Gammon explains with Arduino example:
How to do multiple things at once ... like cook bacon and eggs

Arduino is so fast you should get appearance of smooth motion.