Advertisement
RuiViana

Sinal_Pedestre

Nov 16th, 2016
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #define carRed 12
  2. #define carYellow 11
  3. #define carGreen 10
  4. #define pedRed 8
  5. #define pedGreen 7
  6. #define button 2
  7. int crossTime = 5000;
  8.  
  9. byte ligar = 0;
  10. //--------------------------------
  11. void setup()
  12. {
  13.   pinMode (carRed, OUTPUT);
  14.   pinMode (carYellow, OUTPUT);
  15.   pinMode (carGreen, OUTPUT);
  16.   pinMode (pedRed, OUTPUT);
  17.   pinMode (pedGreen, OUTPUT);
  18.   pinMode (button, INPUT);
  19.  
  20.   digitalWrite(carGreen, HIGH);
  21.   digitalWrite(pedRed, HIGH);
  22. }
  23. //--------------------------------
  24. void loop()
  25. {
  26.   while (digitalRead(button) == HIGH)       // Enquanto botao esta pressionado
  27.   { // Evita bouncing
  28.     delay(30);
  29.     if (digitalRead(button) == LOW)         // Se botao foi liberado
  30.     {
  31.       ligar ++;                             // Incrementa contadoer
  32.     }
  33.   }
  34.   if (ligar == 6)                           // Se contador igual a 6
  35.   {
  36.     digitalWrite(carGreen, LOW);            // Car Verde Off
  37.     digitalWrite(carYellow, HIGH);          // Car amarelo On
  38.     delay(2000);
  39.     digitalWrite(carYellow, LOW);           // Car amarelo Off
  40.     digitalWrite(carRed, HIGH);             // Car vermelho On
  41.     delay(1000);
  42.     digitalWrite(pedRed, LOW);              // Car vermelho Off
  43.     digitalWrite(pedGreen, HIGH);           // Ped verde On
  44.     delay(crossTime);
  45.     for (int x = 0; x < 10; x++)            // Faz o Led Verde do Pedestre piscar 9 vezes.
  46.     {
  47.       digitalWrite(pedGreen, HIGH);         // Acender Led Ped Verde
  48.       delay(250);
  49.       digitalWrite(pedGreen, LOW);          // Apagar Led Ped Verde
  50.       delay(250);
  51.     }
  52.     digitalWrite(pedRed, HIGH);             // ped vermelho On
  53.     delay(500);
  54.     digitalWrite(carYellow, HIGH);          // Car amarelo On
  55.     digitalWrite(carRed, LOW);              // Car vermelho Off
  56.     delay(1000);
  57.     digitalWrite(carGreen, HIGH);           // Car verde On
  58.     digitalWrite(carYellow, LOW);           // Car amarelo Off
  59.     ligar = 0;                              // Zera contador
  60.   }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement