// Projeto 4 – Semáforo interativo int carRed = 12; // estabelece o semáforo para carros int carYellow = 11; int carGreen = 10; int pedRed = 9; // estabelece o semáforo para pedestres int pedGreen = 8; int button = 2; // pino do botão int crossTime = 5000; // tempo para que os pedestres atravessem unsigned long changeTime; // tempo desde que o botão foi pressionado void setup() { pinMode(carRed, OUTPUT); pinMode(carYellow, OUTPUT); pinMode(carGreen, OUTPUT); pinMode(pedRed, OUTPUT); pinMode(pedGreen, OUTPUT); pinMode(button, INPUT); // botão no pino 2 // acende a luz verde digitalWrite(carGreen, HIGH); digitalWrite(pedRed, HIGH); } void loop() { int state = digitalRead(button); /* verifica se o botão foi pressionado e se transcorreram 5 segundos desde a última vez que isso ocorreu */ if (state == HIGH && (millis() - changeTime) > 5000) { // Chama a função para alterar as luzes changeLights(); } } void changeLights() { digitalWrite(carGreen, LOW); // apaga o verde digitalWrite(carYellow, HIGH); // acende o amarelo delay(2000); // espera 2 segundos digitalWrite(carYellow, LOW); // apaga o amarelo digitalWrite(carRed, HIGH); // acende o vermelho delay(1000); // espera 1 segundo, por segurança digitalWrite(pedRed, LOW); // apaga o vermelho dos pedestres digitalWrite(pedGreen, HIGH); // acende o verde dos pedestres delay(crossTime); // espera por um intervalo de tempo predefinido // pisca o verde dos pedestres for (int x=0; x<10; x++) { digitalWrite(pedGreen, HIGH); delay(250); digitalWrite(pedGreen, LOW); delay(250); } // acende o vermelho dos pedestres digitalWrite(pedRed, HIGH); delay(500); digitalWrite(carYellow, HIGH); // acende o amarelo digitalWrite(carRed, LOW); // apaga o vermelho delay(1000); digitalWrite(carGreen, HIGH); // acende o verde digitalWrite(carYellow, LOW); // apaga o amarelo // registra o tempo desde a última alteração no semáforo changeTime = millis(); // depois retorna para o loop principal do programa }
Standard input is empty
prog.c: In function ‘setup’: prog.c:11:1: warning: implicit declaration of function ‘pinMode’ [-Wimplicit-function-declaration] pinMode(carRed, OUTPUT); ^~~~~~~ prog.c:11:17: error: ‘OUTPUT’ undeclared (first use in this function) pinMode(carRed, OUTPUT); ^~~~~~ prog.c:11:17: note: each undeclared identifier is reported only once for each function it appears in prog.c:16:17: error: ‘INPUT’ undeclared (first use in this function) pinMode(button, INPUT); // botão no pino 2 ^~~~~ prog.c:18:1: warning: implicit declaration of function ‘digitalWrite’ [-Wimplicit-function-declaration] digitalWrite(carGreen, HIGH); ^~~~~~~~~~~~ prog.c:18:24: error: ‘HIGH’ undeclared (first use in this function) digitalWrite(carGreen, HIGH); ^~~~ prog.c: In function ‘loop’: prog.c:22:13: warning: implicit declaration of function ‘digitalRead’ [-Wimplicit-function-declaration] int state = digitalRead(button); ^~~~~~~~~~~ prog.c:25:14: error: ‘HIGH’ undeclared (first use in this function) if (state == HIGH && (millis() - changeTime) > 5000) { ^~~~ prog.c:25:23: warning: implicit declaration of function ‘millis’ [-Wimplicit-function-declaration] if (state == HIGH && (millis() - changeTime) > 5000) { ^~~~~~ prog.c:28:1: warning: implicit declaration of function ‘changeLights’ [-Wimplicit-function-declaration] changeLights(); ^~~~~~~~~~~~ prog.c: At top level: prog.c:31:6: warning: conflicting types for ‘changeLights’ void changeLights() { ^~~~~~~~~~~~ prog.c:28:1: note: previous implicit declaration of ‘changeLights’ was here changeLights(); ^~~~~~~~~~~~ prog.c: In function ‘changeLights’: prog.c:32:24: error: ‘LOW’ undeclared (first use in this function) digitalWrite(carGreen, LOW); // apaga o verde ^~~ prog.c:33:25: error: ‘HIGH’ undeclared (first use in this function) digitalWrite(carYellow, HIGH); // acende o amarelo ^~~~ prog.c:34:1: warning: implicit declaration of function ‘delay’ [-Wimplicit-function-declaration] delay(2000); // espera 2 segundos ^~~~~
Standard output is empty