// Práctica 1, apartado 7.2: SEMÁFOROS DE PEATONES Y COCHES
const int ledCR=23; //GPIO Luz coches ROJA
const int ledCA=22; //GPIO Luz coches AMARILLA
const int ledCV=21; //GPIO Luz coches VERDE
const int ledPA=12; //GPIO Luz peatones AMARILLA
const int ledPV=13; //GPIO Luz peatones VERDE
void setup()
{
pinMode(ledCR, OUTPUT);
pinMode(ledCA, OUTPUT);
pinMode(ledCV, OUTPUT);
pinMode(ledPA, OUTPUT);
pinMode(ledPV, OUTPUT);
Serial.begin(115200);
Serial.println("Prática semáforo coches y peatones");
}
void parpadeoPA(int ledPINPA, int n) // Parpadeo semáforo amarillo para peatones
{
for (int i = 0; i < n; i++) // n es en número de ciclos que el led parpadea
{
digitalWrite(ledPINPA, HIGH);
delay(250);
digitalWrite(ledPINPA, LOW);
delay(250);
}
}
void loop()
{
Serial.println("Luz roja coches encendida");
Serial.println("Luz verde peatones encendida");
digitalWrite(ledCR, HIGH); // Luz roja semáforo coches encendida
digitalWrite(ledPV, HIGH); //Luz verde semáforo peatones encendida
delay(5000);
Serial.println("Luces roja y amarilla coches encendidas");
Serial.println("Luz amarilla peatones parpadeando");
digitalWrite(ledPV, LOW); //Luz verde semáforo peatones apagada
digitalWrite(ledCA, HIGH); // Luz amarilla semáforo coches encendida
parpadeoPA(ledPA, 4); //Luz amarilla semáforo peatones parpadeando (500 ms por ciclo x 4 ciclos = 2000 ms)
Serial.println("Luz verde coches encendida");
Serial.println("Luz amarilla peatones parpadeando");
digitalWrite(ledCV, HIGH); // Luz verde semáforo coches encendida
digitalWrite(ledCA, LOW); // Luz amarilla semáforo coches apagada
digitalWrite(ledCR, LOW); // Luz roja semáforo coches apagada
parpadeoPA(ledPA, 10); //Luz amarilla semáforo peatones parpadeando (500 ms por ciclo x 10 ciclos = 5000 ms)
Serial.println("Luces verde y amarilla coches encendidas");
Serial.println("Luz amarilla peatones parpadeando");
digitalWrite(ledCA, HIGH); // Luz amarilla semáforo coches encendida
parpadeoPA(ledPA, 4); //Luz amarilla semáforo peatones parpadeando (500 ms por ciclo x 4 ciclos = 2000 ms)
digitalWrite(ledCA, LOW); // Luz amarilla semáforo coches apagada
digitalWrite(ledCV, LOW); // Luz verde semáforo coches apagada
}