//Aluno: Leonardo Araujo Armelin
//Projeto semáforo com interrupção
volatile int teste = 0;
void setup() {
DDRD = 0b11110011;
DDRB = 0b00000011;
attachInterrupt(digitalPinToInterrupt(3), interrupt, FALLING);
}
void interrupt(){
teste = !teste;
}
void semaforo(){
PORTD = 0b00100100; //s1 aberto s2 fechado
PORTB = 0b00000010;
delay(5000);
PORTD = 0b01000100; //s1 amarelo s2 fechado
PORTB = 0b00000010;
delay(2000);
PORTD = 0b10000001; //s1 fechado s2 aberto
PORTB = 0b00000010;
delay(5000);
PORTD = 0b10000010; //s1 fechado s2 amarelo
PORTB = 0b00000010;
delay(2000);
}
void semaforo_pedestre(){
PORTD = 0b10000100;
PORTB = 0b00000001;
delay(5000);
PORTD = 0b10000010;
PORTB = 0b00000010;
delay(2000);
semaforo();
}
void loop(){
if(teste){
semaforo_pedestre();
teste = 0;
}
else{
semaforo();
}
}