Guest User

ping

a guest
Apr 18th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1.  
  2. const int entrada = 13;
  3. const int timeout = 500000; // meio segundo
  4.  
  5. void setup() {
  6. pinMode(entrada, INPUT);
  7. Serial.begin(9600);
  8. }
  9.  
  10. void loop()
  11. {
  12. long T_ON = 0;
  13. long T_OFF = 0;
  14. long T_TOTAL = 0;
  15. long FREQ = 0;
  16.  
  17. T_ON = pulseIn(entrada, HIGH, timeout);
  18. T_OFF = pulseIn(entrada, LOW, timeout);
  19. T_TOTAL = (T_ON + T_OFF);
  20.  
  21. if(T_TOTAL){
  22. Serial.print("T: ");
  23. Serial.print(T_TOTAL);
  24. Serial.print(" ms");
  25.  
  26. Serial.print("Freq: ");
  27. Serial.print((1000000/T_TOTAL));
  28. Serial.println(" Hz");
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment