/*** Global variables ***/ int Led_Azul=3; int Led_Rojo=12; int Pulsador=2; int Pulsado; int Sin_Pulsar; int T_Destello=50; int T_Entre_Destello=200; int Secuencia=0; int Secuencia_Max=4; int Contador=0; int Iteraciones; int i; /*** Function declaration ***/ void Sec_Apagado (); void Sec_Destellos_Juntos (); void Sec_Destellos_Alternos (); void Sec_3_Destellos_Alternos (); void Sec_4_Destellos_Alternos (); void Retardo (); void setup() { Pulsado=LOW; Sin_Pulsar=HIGH; Serial.begin(9600); } void loop() { pinMode(Pulsador,INPUT); if (Secuencia == 0) { Sec_Apagado(); } if (Secuencia == 1) { Sec_3_Destellos_Alternos(); } if (Secuencia == 2) { Sec_Destellos_Juntos(); } if (Secuencia == 3) { Sec_4_Destellos_Alternos(); } if (Secuencia == 4) { Sec_Destellos_Alternos(); } pinMode(Pulsador,INPUT); if (digitalRead(Pulsador) == Pulsado) { delay(11); pinMode(Pulsador,INPUT); pinMode(Pulsador,INPUT); if (digitalRead(Pulsador) == Pulsado) { pinMode(Pulsador,INPUT); while (digitalRead(Pulsador) == Pulsado) { } Secuencia=Secuencia + 1; if (Secuencia > Secuencia_Max) { Secuencia=0; } } } } /*** Function definition ***/ void Retardo (int Iteraciones){ Contador=0; while (Contador <= Iteraciones) { pinMode(Pulsador,INPUT); if (digitalRead(Pulsador) == Pulsado) { break; } Contador=Contador + 1; delay(1); } return ; } void Sec_Apagado () { pinMode(Pulsador,INPUT); while (digitalRead(Pulsador) == Sin_Pulsar) { pinMode(Led_Azul,OUTPUT); digitalWrite(Led_Azul,LOW); pinMode(Led_Rojo,OUTPUT); digitalWrite(Led_Rojo,LOW); } } void Sec_Destellos_Juntos () { pinMode(Pulsador,INPUT); while (digitalRead(Pulsador) == Sin_Pulsar) { pinMode(Led_Azul,OUTPUT); digitalWrite(Led_Azul,HIGH); pinMode(Led_Rojo,OUTPUT); digitalWrite(Led_Rojo,HIGH); Retardo(T_Destello); pinMode(Led_Azul,OUTPUT); digitalWrite(Led_Azul,LOW); pinMode(Led_Rojo,OUTPUT); digitalWrite(Led_Rojo,LOW); Retardo(T_Entre_Destello); } } void Sec_3_Destellos_Alternos () { pinMode(Pulsador,INPUT); while (digitalRead(Pulsador) == Sin_Pulsar) { i=0; for (int i=0; i<=2; i++) { pinMode(Led_Azul,OUTPUT); digitalWrite(Led_Azul,HIGH); Retardo(T_Destello); pinMode(Led_Azul,OUTPUT); digitalWrite(Led_Azul,LOW); Retardo(T_Destello); } Retardo(T_Destello); i=0; for (int i=0; i<=2; i++) { pinMode(Led_Rojo,OUTPUT); digitalWrite(Led_Rojo,HIGH); Retardo(T_Destello); pinMode(Led_Rojo,OUTPUT); digitalWrite(Led_Rojo,LOW); Retardo(T_Destello); } Retardo(T_Entre_Destello); } } void Sec_4_Destellos_Alternos () { pinMode(Pulsador,INPUT); while (digitalRead(Pulsador) == Sin_Pulsar) { i=0; for (int i=0; i<=3; i++) { pinMode(Led_Azul,OUTPUT); digitalWrite(Led_Azul,HIGH); Retardo(T_Destello); pinMode(Led_Azul,OUTPUT); digitalWrite(Led_Azul,LOW); Retardo(T_Destello); } Retardo(T_Destello); i=0; for (int i=0; i<=3; i++) { pinMode(Led_Rojo,OUTPUT); digitalWrite(Led_Rojo,HIGH); Retardo(T_Destello); pinMode(Led_Rojo,OUTPUT); digitalWrite(Led_Rojo,LOW); Retardo(T_Destello); } Retardo(T_Entre_Destello); } } void Sec_Destellos_Alternos () { pinMode(Pulsador,INPUT); while (digitalRead(Pulsador) == Sin_Pulsar) { pinMode(Led_Azul,OUTPUT); digitalWrite(Led_Azul,HIGH); pinMode(Led_Rojo,OUTPUT); digitalWrite(Led_Rojo,LOW); Retardo(T_Entre_Destello); pinMode(Led_Azul,OUTPUT); digitalWrite(Led_Azul,LOW); pinMode(Led_Rojo,OUTPUT); digitalWrite(Led_Rojo,HIGH); Retardo(T_Entre_Destello); } }