Advertisement
RuiViana

Ja_Contei

Mar 28th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. int rele_1 = 5;
  2. int rele_2 = 6;
  3. int botao_1 = 7;
  4. int botao_2 = 4;
  5.  
  6. int status_rele_1 = 0;
  7. int status_rele_2 = 0;
  8.  
  9. int leiturabotao_1 = 0;
  10. int leiturabotao_2 = 0;
  11.  
  12. int contador = 0;
  13. byte Ja_Contei = 0;
  14.  
  15. unsigned long tempoAtual = 0;
  16. unsigned long tempoInicial;
  17. unsigned long tempoSet = 30000;
  18. //------------------------------
  19. void setup()
  20. {
  21.   Serial.begin(9600);
  22.   pinMode(rele_1, OUTPUT);
  23.   pinMode(rele_2, OUTPUT);
  24.   pinMode(botao_1, INPUT_PULLUP);
  25.   pinMode(botao_2, INPUT);
  26.  
  27.   digitalWrite(rele_1, LOW);
  28.   digitalWrite(rele_2, LOW);
  29. }
  30. //------------------------------
  31. void loop()
  32. {
  33.   // contador=0;
  34.   status_rele_1 = digitalRead(rele_1);
  35.   status_rele_2 = digitalRead(rele_2);
  36.   leiturabotao_1 = digitalRead(botao_1);
  37.   leiturabotao_2 = digitalRead(botao_2);
  38.   if ( leiturabotao_1 != 0)
  39.   {
  40.     digitalWrite( rele_1, HIGH);
  41.     Ja_Contei = 1;
  42.   }
  43.   else
  44.   {
  45.     digitalWrite( rele_1, LOW);
  46.     Ja_Contei = 0;
  47.   }
  48.   if (status_rele_1 != 0)
  49.   {
  50.     {
  51.       if (Ja_Contei == 0)
  52.       {
  53.         contador ++;
  54.       }
  55.     }
  56.   }
  57.   if (contador == 5)
  58.   {
  59.     digitalWrite( rele_1, LOW);
  60.     digitalWrite( rele_2, HIGH);
  61.   }
  62.   if (status_rele_2 != 0)
  63.   {
  64.     digitalWrite( rele_1, LOW);
  65.   }
  66.   if (leiturabotao_2 != 0)
  67.   {
  68.     tempoAtual = millis();
  69.     if (((millis()) - tempoAtual) > tempoSet)
  70.     {
  71.       // passou 2 minutos
  72.       digitalWrite( rele_2, LOW);
  73.       contador = 0;
  74.       tempoAtual = millis();
  75.     }
  76.   }
  77.   Serial.println(contador);
  78.   Serial.println(leiturabotao_1);
  79.   Serial.println(leiturabotao_2);
  80.   delay (1000);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement