void setup() {
// put your setup code here, to run once:
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
Serial.begin(9600);
analogReference(DEFAULT);
}
void loop() {
// put your main code here, to run repeatedly:
//Leitura do tempo definido pelo potenciômetro:
long int timer = analogRead(A0);
float timer_V = 5*timer/1023;
float time = map(timer_V,0,5,10,30);
//Serial.println(time,2);
//Definição dos tempos de cada sinal:
float time_green = time*1000;
float time_yellow = (time-6.75)*1000;
float time_red = time*1000;
//Sinal verde:
digitalWrite(10, HIGH);
delay(time_green);
digitalWrite(10, LOW);
//Sinal amarelo:
digitalWrite(8, HIGH);
delay(time_yellow);
digitalWrite(8, LOW);
delay(250);
pisca_amarelo();
//Sinal vermelho:
digitalWrite(9, HIGH);
delay(time_red);
digitalWrite(9, LOW);
}
void pisca_amarelo() {
digitalWrite(8, HIGH);
delay(2000);
digitalWrite(8, LOW);
delay(250);
digitalWrite(8, HIGH);
delay(2000);
digitalWrite(8, LOW);
delay(250);
digitalWrite(8, HIGH);
delay(2000);
digitalWrite(8, LOW);
}