RuiViana

Med_Tempos.ino

Nov 1st, 2018
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1.  
  2. #define sinal1 3
  3. #define sinal2 4
  4. unsigned long tempo1;
  5. unsigned long tempo2;
  6. unsigned long tempo3;
  7. unsigned long regValSin1;
  8. unsigned long regValSin2;
  9. bool flag1 = LOW;
  10. bool flag2 = LOW;
  11. bool flag3 = LOW;
  12. //------------------------------------------------------
  13. void setup()
  14. {
  15.   Serial.begin(9600);
  16.   pinMode (sinal1, INPUT_PULLUP);
  17.   pinMode (sinal2, INPUT_PULLUP);
  18.   Serial.println("Controle");
  19. }
  20. //------------------------------------------------------
  21. void loop()
  22. {
  23.   if (flag1 == LOW)
  24.   {
  25.     if (digitalRead(sinal1) == HIGH)
  26.     {
  27.       tempo1 = millis();
  28.       flag1 = HIGH;
  29.     }
  30.   }
  31.   if (flag1 == HIGH)
  32.   {
  33.     if (digitalRead(sinal1) == LOW)
  34.     {
  35.       regValSin1 = millis() - tempo1;
  36.       Serial.print("pulso1 = : ");
  37.       Serial.println(regValSin1);
  38.       flag1 = LOW;
  39.       flag3 = HIGH;
  40.       tempo3 = millis();
  41.     }
  42.   }
  43.  
  44.   if (flag3 == HIGH)
  45.   {
  46.     if (digitalRead(sinal1) == LOW and digitalRead(sinal2) == HIGH)
  47.     {
  48.       Serial.print("Espaço = : ");
  49.       Serial.println(millis() - tempo3);
  50.       flag3 = LOW;
  51.     }
  52.  
  53.   }
  54.  
  55.   if (flag2 == LOW)
  56.   {
  57.     if (digitalRead(sinal2) == HIGH)
  58.     {
  59.       tempo2 = millis();
  60.       flag2 = HIGH;
  61.     }
  62.   }
  63.   if (flag2 == HIGH)
  64.   {
  65.     if (digitalRead(sinal2) == LOW)
  66.     {
  67.       regValSin2 = millis() - tempo2;
  68.       Serial.print("pulso2 = : ");
  69.       Serial.println(regValSin2);
  70.       Serial.println(" ");
  71.       flag2 = LOW;
  72.     }
  73.   }
  74. }
Add Comment
Please, Sign In to add comment