Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define sinal1 3
- #define sinal2 4
- unsigned long tempo1;
- unsigned long tempo2;
- unsigned long tempo3;
- unsigned long regValSin1;
- unsigned long regValSin2;
- bool flag1 = LOW;
- bool flag2 = LOW;
- bool flag3 = LOW;
- //------------------------------------------------------
- void setup()
- {
- Serial.begin(9600);
- pinMode (sinal1, INPUT_PULLUP);
- pinMode (sinal2, INPUT_PULLUP);
- Serial.println("Controle");
- }
- //------------------------------------------------------
- void loop()
- {
- if (flag1 == LOW)
- {
- if (digitalRead(sinal1) == HIGH)
- {
- tempo1 = millis();
- flag1 = HIGH;
- }
- }
- if (flag1 == HIGH)
- {
- if (digitalRead(sinal1) == LOW)
- {
- regValSin1 = millis() - tempo1;
- Serial.print("pulso1 = : ");
- Serial.println(regValSin1);
- flag1 = LOW;
- flag3 = HIGH;
- tempo3 = millis();
- }
- }
- if (flag3 == HIGH)
- {
- if (digitalRead(sinal1) == LOW and digitalRead(sinal2) == HIGH)
- {
- Serial.print("Espaço = : ");
- Serial.println(millis() - tempo3);
- flag3 = LOW;
- }
- }
- if (flag2 == LOW)
- {
- if (digitalRead(sinal2) == HIGH)
- {
- tempo2 = millis();
- flag2 = HIGH;
- }
- }
- if (flag2 == HIGH)
- {
- if (digitalRead(sinal2) == LOW)
- {
- regValSin2 = millis() - tempo2;
- Serial.print("pulso2 = : ");
- Serial.println(regValSin2);
- Serial.println(" ");
- flag2 = LOW;
- }
- }
- }
Add Comment
Please, Sign In to add comment