Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define carRed 12
- #define carYellow 11
- #define carGreen 10
- #define pedRed 8
- #define pedGreen 7
- #define button 2
- int crossTime = 5000;
- byte ligar = 0;
- //--------------------------------
- void setup()
- {
- pinMode (carRed, OUTPUT);
- pinMode (carYellow, OUTPUT);
- pinMode (carGreen, OUTPUT);
- pinMode (pedRed, OUTPUT);
- pinMode (pedGreen, OUTPUT);
- pinMode (button, INPUT);
- digitalWrite(carGreen, HIGH);
- digitalWrite(pedRed, HIGH);
- }
- //--------------------------------
- void loop()
- {
- while (digitalRead(button) == HIGH) // Enquanto botao esta pressionado
- { // Evita bouncing
- delay(30);
- if (digitalRead(button) == LOW) // Se botao foi liberado
- {
- ligar ++; // Incrementa contadoer
- }
- }
- if (ligar == 6) // Se contador igual a 6
- {
- digitalWrite(carGreen, LOW); // Car Verde Off
- digitalWrite(carYellow, HIGH); // Car amarelo On
- delay(2000);
- digitalWrite(carYellow, LOW); // Car amarelo Off
- digitalWrite(carRed, HIGH); // Car vermelho On
- delay(1000);
- digitalWrite(pedRed, LOW); // Car vermelho Off
- digitalWrite(pedGreen, HIGH); // Ped verde On
- delay(crossTime);
- for (int x = 0; x < 10; x++) // Faz o Led Verde do Pedestre piscar 9 vezes.
- {
- digitalWrite(pedGreen, HIGH); // Acender Led Ped Verde
- delay(250);
- digitalWrite(pedGreen, LOW); // Apagar Led Ped Verde
- delay(250);
- }
- digitalWrite(pedRed, HIGH); // ped vermelho On
- delay(500);
- digitalWrite(carYellow, HIGH); // Car amarelo On
- digitalWrite(carRed, LOW); // Car vermelho Off
- delay(1000);
- digitalWrite(carGreen, HIGH); // Car verde On
- digitalWrite(carYellow, LOW); // Car amarelo Off
- ligar = 0; // Zera contador
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement