// *********************************************************************************
//
// Sirene
//
// *********************************************************************************
int LED_Azul = 7;
int LED_Verde = 6;
int LED_Amarelo = 5;
int LED_Vermelho = 4;
int Caixa_Som = 8;
// *********************************************************************************
void setup()
{
pinMode( LED_Azul, OUTPUT );
pinMode( LED_Verde, OUTPUT );
pinMode( LED_Amarelo, OUTPUT );
pinMode( LED_Vermelho, OUTPUT );
pinMode( Caixa_Som, OUTPUT );
}
// *********************************************************************************
int delta = 50;
void loop()
{
for (int i=500; i<900; i+=delta)
{
troca_LED(i);
tone(Caixa_Som, i); delay(delta);
}
for (int i=900; i>500; i-=delta)
{
troca_LED(i);
tone(Caixa_Som, i); delay(delta);
}
}
// *********************************************************************************
void troca_LED( int i )
{
if ( i < 600 ) { Acende_Azul(); }
else if ( i < 700 ) { Acende_Verde(); }
else if ( i < 800 ) { Acende_Amarelo(); }
else if ( i < 900 ) { Acende_Vermelho(); }
}
// *********************************************************************************
void Apaga_Tudo()
{
digitalWrite( LED_Azul, LOW );
digitalWrite( LED_Verde, LOW );
digitalWrite( LED_Amarelo, LOW );
digitalWrite( LED_Vermelho, LOW );
}
void Acende_Azul() { Apaga_Tudo(); digitalWrite( LED_Azul, HIGH ); }
void Acende_Verde() { Apaga_Tudo(); digitalWrite( LED_Verde, HIGH ); }
void Acende_Amarelo() { Apaga_Tudo(); digitalWrite( LED_Amarelo, HIGH ); }
void Acende_Vermelho() { Apaga_Tudo(); digitalWrite( LED_Vermelho, HIGH ); }