help!

hi everybody
i'm trying to automate my audio system with arduino: if audio is detected on one input ,the amp is powered up and this input is routed to the amp.
aditionnaly iuse a relay based attenuator to manage volume. if there is no audio at all, everything is turned off after 10seconds.
everything works fine exept that if the temporisation is running i cant stop it with incoming audio.
could somebody explain to me how can i do that.
thank you
here is the code:

// define inputs
int inputPin0=A0; // volume pot input
int inputPin1=A1; // input 1 signal detector
int inputPin2=A2; // input 2 signal detector
int inputPin3=A3; // input 2 signal detector

// define outputs
int latchPin = 8; // Pin connected to ST_CP of 74HC595
int clockPin = 12; // Pin connected to SH_CP of 74HC595
int dataPin = 11; // Pin connected to DS of 74HC595
int powerPin =4; // pin controling power relay

//define variables
int volume; // value sent to 74HC595, bit 0 to 5 controling relay based attenuator, bit 6&7 controling input selection relays
int in1signal; // value of signal 1
int in2signal; // value of signal 2
int in3signal; // value of signal 3
int tempo; // temporisation value

void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(powerPin, OUTPUT);
pinMode(inputPin0, INPUT);
pinMode(inputPin1, INPUT);
pinMode(inputPin2, INPUT);
pinMode(inputPin3, INPUT);
volume=0;
Serial.begin (9600);
}

void loop()
{

in1signal= analogRead (inputPin1);
in2signal= analogRead (inputPin2);
in3signal= analogRead (inputPin3);

if ((in1signal!=0) && (in2signal==0) && (in3signal==0)) // if there is a signal on input1
{powerPin=HIGH; // turn power on
volume=31; // set fixed volume of tv box input
tempo=0; // reset temporisation
Serial.print ("tv box selected" ); // send to serial monitor for debug
Serial.println (volume ); // send to serial monitor for debug
}

if ((in1signal==0) && (in2signal!=0) && (in3signal==0)) // if there is a signal on input2
{powerPin=HIGH; // turn power on
volume=analogRead (inputPin0); // read volume pot
volume=map (volume, 0, 1023, 65, 127); // set volume with bit 6 high to select input2 relay
tempo=0; // reset temporisation
Serial.print ("cd selected" ); // send to serial monitor for debug
Serial.println (volume ); // send to serial monitor for debug
}

if ((in1signal==0) && (in2signal==0) && (in3signal!=0)) // if there is a signal on input3
{powerPin=HIGH; // turn power on
volume=analogRead (inputPin0); // read volume pot
volume=map (volume, 0, 1023, 192, 255); // set volume with bit 6&7 high to select input3 relay
tempo=0; // reset temporisation
Serial.print ("tuner selected" ); // send to serial monitor for debug
Serial.println (volume ); // send to serial monitor for debug
}

if (in1signal+in2signal+in3signal==0)
{
while (tempo<10)
{ delay (1000); // wait for a second
tempo++; // increase "tempo"
Serial.print ("temporisation =" ); // send to serial monitor for debug
Serial.println (tempo); // send to serial monitor for debug
}
if (tempo=30) // if tempo is 30
{volume=0; // turn off sound
Serial.println ("mute" ); // send to serial monitor for debug
delay (1000);
powerPin=LOW; // turn off power
Serial.println ("power off" ); // send to serial monitor for debug
tempo=0; // reset temporisation
}

}

// send data to hc74595
digitalWrite(latchPin, LOW); // take the latchPin low so the relays don't change while you're sending in bits:
shiftOut(dataPin, clockPin, MSBFIRST, volume); // shift out the bits:
digitalWrite(latchPin, HIGH); // take the latch pin high so the relays will be activated:

}

Modify that post.
Select the code and hit the # icon to put the proper code tags round it. Then save the changes.

Next post a schematic of what your circuit is.

What is a "temporisation"?

What is a "temporisation"?

Sounds like a mode of transportation from Star Trek.

'inputPin0' seems like a poor choice of name for the volume control input.

Having three inputs all handled and managed in the same way makes me think that you should be managing them in an array.

When you are deciding which input to connect to, your logic only works when there is exactly one non-zero input. I suggest that instead you define an order of precedence between the input. For example, you could say that input1 is selected if it is active; input2 is selected if it is active and input1 isn't; input3 is selected if it is active and input1 and input2 are not active. You could implement that easily by testing each input in order and stopping when you find the first active one.

How is your sound input connected to your analogue inputs? You are testing for a zero signal, but depending how you're connecting you may find that doesn't happen very often or at all. You may need to test for the value being below a threshold rather than zero. Is an instantaneous zero signal sufficient to decide there is no input? I would have thought it made more sense to check for the signal remaining zero for some time - for example, ten seconds. To achieve that would require a significant change to that final block of code dealing with tempo. As it stands, all it seems to do is delay for 10 seconds, assign tempo=30 and go into mute mode. Perhaps you intended that "if(tempo = 30)" to be an == rather than assignment, although that doesn't make any sense either since tempo will never equal 30 at that point.

What I'd do if it were me is have an unsigned long that holds the value of millis() when the last sound was detected, updated to millis() each time sound is detected. If that value indicates that you haven't heard sound in the last 10 seconds (or whatever), go to mute mode. I'd ditch the ideal of tempo altogether.

It's Time.

if the temporisation is running i cant stop it

He is trying to stop Time.

He is trying to stop Time.

He must be stopped!

tempo is speed, not time.
And it can be stopped easily

tempo = 0;