read pulsed input

  if (flag_handset == HIGH && flag_silent == HIGH)
  {
    if (flag_call == LOW)
    {
      lastTimeLow = millis();
    }
    digitalWrite(outputPin, millis()-lastTimeLow < delay_call); 
  }
  else
  {
    digitalWrite(outputPin, LOW);
  }
}

That if-else structure you tried to implement the timer in nullifies the timer, it only measures elapsed time under 3 true conditions.

You could put a task in loop that only watches the pin and sets a global status byte that the rest of the code can read. That is how I debounce contact buttons, the decision part(s) of the sketch read the status. As long as the rest of the sketch does not block, my buttons detect fast and true -- the buttons task does not depend on conditions inside other code to run, it runs as often as void loop().

Anyhow you can reduce code complexity by breaking a job down into tasks with maybe some or all as cases in a finite state machine, which is simpler working than the name sounds.

@GoForSmoke, that sounds interesting. Can ou may send me an example of such a state machine could look like?

http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

One problem you will have is how to detect "input has not been LOW for a while" ('off' condition) when the processor only wakes up on a CHANGE in input. Say the input goes HIGH and stays that way for several seconds. That means your signal is "off" but since it is not changing there is no interrupt and your sketch will remain asleep.

One way to do it is to set Timer2 to interrupt after running for 800 milliseconds (roughly). On every input change, restart Timer2, set output to HIGH, and go back to sleep. If that Timer2 interrupt wakes up the processor, you signal has been HIGH for a while, signaling your 'off' condition. Set the output to LOW, turn off Timer2, and go back to sleep.

snash82:
@GoForSmoke, that sounds interesting. Can ou may send me an example of such a state machine could look like?

Nick Gammon is a senior member here, this is from his blog on handling serial data:

State Machine

Another way of processing incoming data, without blocking, is to set up a "state machine". Effectively this means looking at each byte in the input stream, and handling it depending on the current state.

As an example, say you had this coming into the serial port:

R4500S80G3

Where Rnnn is RPM, Snnnn is speed, and Gnnnn is the gear setting.

The state machine below switches state when it gets a letter "R", "S" or "G". Otherwise it processes incoming digits by multiplying the previous result by 10, and adding in the new one.

When switching states, if first handles the previous state. So for example, after getting R4500 when the "S" arrives, we call the ProcessRPM function, passing it 4500.

This has the advantage of handling long messages without even needing any buffer, thus saving RAM. You can also process message as soon as the state changes, rather than waiting for end-of-line.

Example state-machine code

// Example state machine reading serial input
// Author: Nick Gammon
// Date: 17 December 2011

// the possible states of the state-machine
typedef enum { NONE, GOT_R, GOT_S, GOT_G } states;

// current state-machine state
states state = NONE;
// current partial number
unsigned int currentValue;

void setup ()
{
Serial.begin (115200);
state = NONE;
} // end of setup

void processRPM (const unsigned int value)
{
// do something with RPM
Serial.print ("RPM = ");
Serial.println (value);
} // end of processRPM

void processSpeed (const unsigned int value)
{
// do something with speed
Serial.print ("Speed = ");
Serial.println (value);
} // end of processSpeed

void processGear (const unsigned int value)
{
// do something with gear
Serial.print ("Gear = ");
Serial.println (value);
} // end of processGear

void handlePreviousState ()
{
switch (state)
{
case GOT_R:
processRPM (currentValue);
break;
case GOT_S:
processSpeed (currentValue);
break;
case GOT_G:
processGear (currentValue);
break;
} // end of switch

currentValue = 0;
} // end of handlePreviousState

void processIncomingByte (const byte c)
{
if (isdigit (c))
{
currentValue *= 10;
currentValue += c - '0';
} // end of digit
else
{

// The end of the number signals a state change
handlePreviousState ();

// set the new state, if we recognize it
switch (c)
{
case 'R':
state = GOT_R;
break;
case 'S':
state = GOT_S;
break;
case 'G':
state = GOT_G;
break;
default:
state = NONE;
break;
} // end of switch on incoming byte
} // end of not digit

} // end of processIncomingByte

void loop ()
{
while (Serial.available ())
processIncomingByte (Serial.read ());

// do other stuff in loop as required

} // end of loop

You could change "unsigned int" to "unsigned long" if you were expecting numbers larger than 65535.

You can break a long process up into pieces and control which one runs with a variable that holds the process state.

The pieces need to run quick so that the machine runs fast and other tasks in loop() run smoothly too.

The non-blocking way to code is explained in the 1st Gammon tutorial link in my sig space below to check out this whole time.

This can get you started with writing code as many pieces that work together: Gammon Forum : Electronics : Microprocessors : How to do multiple things at once ... like cook bacon and eggs
If you do both tutorials in order and understand and can adapt that into your own coding then your limit is how well you can express what you want in C/C++ or other language.

In your IDE Examples be sure to cover section 5.
When you open the Arduino IDE also open your web browser. There's a banner at the top of the forum page with HOME STORE etc, click RESOURCES and then REFERENCE. If you see code in the example that you have a question about, see if it's in the Reference Page. Use the browser Find tool to save time, the unfamiliar code may be from a library but if it's in the reference you get instant help.