#define red 34
#define yllw 25
#define green 12
#define but 15
#define noped 2
#define yeped 4
unsigned long changetime;
int cont;
void setup() {
Serial.begin(115200);
pinMode(red, OUTPUT);
pinMode(yllw, OUTPUT);
pinMode(green, OUTPUT);
pinMode(noped, OUTPUT);
pinMode(yeped, OUTPUT);
pinMode(but, INPUT_PULLUP);
}
void loop() {
Serial.println("AGUARDE, Tráfego em andamento. . .");
digitalWrite(green, 1);
digitalWrite(red, 0);
digitalWrite(noped, 1);
cont=25;
for (int j=0;j<25;j++){
cont--;
delay(1000);
Serial.print("Espere mais ");
Serial.print(cont);
Serial.print(" segundos.\n");
}
while(true){
Serial.println("\nAtento: Faixa LIBERADA.");
Serial.println("Aperte o botão!!");
delay(1000);
int leitura = digitalRead(but);
if (leitura == 0 && (millis() - changetime) > 25000){
semaforo();
}
}
}
void semaforo() {
delay(1000);
digitalWrite(green,0);//desliga verde carros
delay(500);
digitalWrite(yellow,1);//liga amarelo carros
delay(4000);
digitalWrite(yellow,0);//desliga amarelo carros
delay(500);
digitalWrite(red,1);//liga vermelho carros
delay(500);
digitalWrite(pedred,0); //desligar vernelho pedestre
digitalWrite(pedgreen,1);//liga verde pedestre
delay(8000);
}