Advertisement
rafaelnfs

FINAL_FINAL

May 26th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. double D  = 0.43;
  3. byte sensor = 2;
  4. byte sensor2 = 3;
  5. volatile unsigned long tiempo = 0;
  6. volatile unsigned long tiempo2 = 0;
  7. volatile unsigned long resultado = 0;
  8.  
  9. volatile double r = 0;
  10. volatile double result = 0;
  11. volatile double v = 0;
  12.  
  13. void setup() {
  14. Serial.begin(9600);
  15.   Serial.println("Iniciando Arduino");
  16.     attachInterrupt(digitalPinToInterrupt(sensor),T1,HIGH);
  17.       attachInterrupt(digitalPinToInterrupt(sensor2),T2,HIGH);
  18. }
  19.  
  20.  
  21. void loop() {
  22.  
  23.  
  24. }
  25.  
  26. void T1(){
  27.   tiempo = millis();
  28.   //Serial.print("Tiempo: ");
  29.     //Serial.println(tiempo);
  30.    
  31. }
  32.  
  33. void T2(){
  34.   tiempo2 = millis();
  35.     //Serial.print("Tiempo2: ");
  36.     //Serial.println(tiempo2);
  37.  
  38.  
  39.       resultado = tiempo2-tiempo;
  40.       result = resultado;
  41.       r = (result/1000);
  42.       v=D/r;
  43.      
  44.         if((resultado >0) and (resultado<1000)){
  45.         /*   Serial.print("resultado: ");
  46.         /Serial.print(resultado);
  47.         Serial.print("-");
  48.         Serial.print((result)/1000);
  49.         */Serial.print("t: ");
  50.         Serial.println(r);
  51.         Serial.print("v: ");
  52.         Serial.print(v);
  53.         Serial.print("m/s");
  54.         }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement