const int ledVermelho = 13;
const int ledAmarelo = 12;
const int ledVerde = 11;
const int ledAzul = 10;
const int botaoVermelho = 7;
const int botaoAmarelo = 6;
const int botaoVerde = 5;
const int botaoAzul = 4;
const int potenciometro = A0;
const int leds[] = {ledVermelho, ledAmarelo, ledVerde, ledAzul};
const int botoes[] = {botaoVermelho, botaoAmarelo, botaoVerde, botaoAzul};
int led = ledVermelho;
unsigned long tempoAtual, tempoPiscar;
unsigned long debounce = 0, tempoDebounce = 1000;
void setup() {
for (int i=0; i<4; i++) {
pinMode(leds[i], OUTPUT);
pinMode(botoes[i], INPUT);
}
tempoAtual = millis();
digitalWrite(led, HIGH);
}
void loop() {
int proximoLed = 0;
tempoPiscar = analogRead(A0) / 1023.0 * 900 + 100;
if (debounce + tempoDebounce < millis()) {
for (int i=0; i<4; i++) {
if (digitalRead(botoes[i])) {
proximoLed = leds[i];
debounce = millis();
break;
}
}
if (proximoLed != 0) {
if (led != proximoLed) {
digitalWrite(led, LOW);
led = proximoLed;
digitalWrite(led, HIGH);
tempoAtual = millis();
}
else {
digitalWrite(led, LOW);
led = 0;
}
}
}
if (led != 0 and millis() > tempoAtual + tempoPiscar) {
digitalWrite(led, not digitalRead(led));
tempoAtual = millis();
}
}