Created
April 12, 2011 14:15
-
-
Save MKo-xx/915557 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long duration; | |
unsigned long time0; | |
unsigned long time; | |
void setup() { | |
Serial.begin(9600); | |
// signal pin | |
pinMode(2, INPUT); | |
// | |
time0 = micros(); | |
} | |
void loop() { | |
// | |
time = micros(); | |
// read pulse width | |
// if there is no pulse during 50000 microseconds | |
// then it returns 0 | |
duration = pulseIn(2, HIGH, 50000); | |
// | |
Serial.print("Time interval = "); | |
Serial.print(time - time0, DEC); | |
Serial.print(", Pulse width = "); | |
Serial.println(duration, DEC); | |
// | |
time0 = time; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment