//***************************************************
//***************************************************
//*** Intermitencia de 3 led a intervalos ********
//*** de 300, 500 y 800ms ************************
//***************************************************
//***************************************************
// Constantes
const int LED1 = 3;
const int LED2 = 5;
const int LED3 = 6;
const int intervalo1 = 300;
const int intervalo2 = 500;
const int intervalo3 = 800;
// Variables globales
int estado1 = LOW;
int estado2 = LOW;
int estado3 = LOW;
unsigned long guardaMillis1 = 0;
unsigned long guardaMillis2 = 0;
unsigned long guardaMillis3 = 0;
//********************************
//*** Configuración ************
//********************************
void setup (){
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
}
//********************************
//*** Programa principal *******
//********************************
void loop ()
{
// LED1, 300ms
if (millis() - guardaMillis1 >= intervalo1)
{
guardaMillis1 = millis();
if(estado1 == LOW) estado1 = HIGH; else estado1 = LOW;
digitalWrite (LED1, estado1);
}
// LED2, 500ms
if (millis() - guardaMillis2 >= intervalo2)
{
guardaMillis2 = millis();
if(estado2 == LOW) estado2 = HIGH; else estado2 = LOW;
digitalWrite (LED2, estado2);
}
// LED3, 800ms
if (millis() - guardaMillis3 >= intervalo3)
{
guardaMillis3 = millis();
if(estado3 == LOW) estado3 = HIGH; else estado3 = LOW;
digitalWrite (LED3, estado3);
}
}
//***********************************
//***********************************
//***********************************