Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. int in=2;
  2.  
  3. void setup(){
  4. Serial.begin(9600);
  5. pinMode(in, INPUT);
  6.  
  7. }
  8. int temi=0;
  9. int tfin=0;
  10. boolean alto=false;
  11. void loop(){
  12.  
  13. }
  14.  
  15.  
  16. void serialEvent() {
  17. if(Serial.read()=='a'){
  18. temi=millis();
  19. while(digitalRead(in)==LOW && Serial.read()!='c'){
  20. alto=true;
  21. tfin=millis();
  22.  
  23. }
  24.  
  25. if(digitalRead(in)==HIGH && alto){
  26. int res=tfin-temi;
  27. Serial.println(res);
  28. alto=false;
  29.  
  30. }
  31. temi=0;
  32. tfin=0;
  33. }
  34. if(Serial.read()=='b'){
  35. temi=0;
  36. tfin=0;
  37. }
  38. }