#define Vd 3
#define Am 4
#define Ve 5
#define Vd2 6
#define Am2 7
#define Ve2 8
#define Buz 9
#define PIR1 10
#define PIR2 12
#define Sens_IR 11
int val_PIR1, val_PIR2, timefase;
int fase= 1;
void setup() {
// put your setup code here, to run once:
pinMode(Vd, OUTPUT);
pinMode(Am, OUTPUT);
pinMode(Ve, OUTPUT);
pinMode(Vd2, OUTPUT);
pinMode(Am2, OUTPUT);
pinMode(Ve2, OUTPUT);
pinMode(Buz, OUTPUT);
pinMode(PIR1, INPUT);
pinMode(PIR2, INPUT);
pinMode(Sens_IR, INPUT);
val_PIR1=0;
val_PIR2=0;
}
void loop() {
//_________________________________________________Contador de Semáforo, Fases + Tempo
timefase=timefase+100;
if(timefase==2000){
fase++;
timefase=0;
}
if(fase >9){
fase=1;
}
//_________________________________________________Controle das fases de Semáforo
if(fase<=4){
digitalWrite(Vd, HIGH);
digitalWrite(Am, LOW);
digitalWrite(Ve, LOW);
digitalWrite(Vd2, LOW);
digitalWrite(Am2, LOW);
digitalWrite(Ve2, HIGH);
}
if(fase == 5){
digitalWrite(Vd, LOW);
digitalWrite(Am, HIGH);
digitalWrite(Ve, LOW);
digitalWrite(Vd2, LOW);
digitalWrite(Am2, HIGH);
digitalWrite(Ve2, LOW);
}
if(fase>5){
digitalWrite(Vd, LOW);
digitalWrite(Am, LOW);
digitalWrite(Ve, HIGH);
digitalWrite(Vd2, HIGH);
digitalWrite(Am2, LOW);
digitalWrite(Ve2, LOW);
}
//_________________________________________________Controle dos Sensores
val_PIR1=digitalRead(PIR1);
val_PIR2=digitalRead(PIR2);
if((fase<=4) && (val_PIR1==LOW)){
if(val_PIR2==HIGH){
fase=5;
}
}
if((fase>5) && (val_PIR2==LOW)){
if(val_PIR1==HIGH){
fase=1;
}
}
delay(100);
}