SHOW:
|
|
- or go back to the newest paste.
| 1 | const int entrada = 13; | |
| 2 | const int timeout = 500000; // meio segundo | |
| 3 | ||
| 4 | void setup() {
| |
| 5 | pinMode(entrada, INPUT); | |
| 6 | Serial.begin(9600); | |
| 7 | } | |
| 8 | ||
| 9 | void loop() | |
| 10 | {
| |
| 11 | long T_ON = 0; | |
| 12 | long T_OFF = 0; | |
| 13 | long T_TOTAL = 0; | |
| 14 | long FREQ = 0; | |
| 15 | ||
| 16 | T_ON = pulseIn(entrada, HIGH, timeout); | |
| 17 | T_OFF = pulseIn(entrada, LOW, timeout); | |
| 18 | T_TOTAL = (T_ON + T_OFF); | |
| 19 | ||
| 20 | if(T_TOTAL){
| |
| 21 | Serial.print("T: ");
| |
| 22 | Serial.print(T_TOTAL); | |
| 23 | Serial.print(" ms");
| |
| 24 | ||
| 25 | Serial.print("Freq: ");
| |
| 26 | Serial.print((1000000/T_TOTAL)); | |
| 27 | Serial.println(" Hz");
| |
| 28 | } | |
| 29 | } |