Last active
December 19, 2015 00:29
-
-
Save electricimp/5869373 to your computer and use it in GitHub Desktop.
This example demonstrates how to use hardware.micros() to capture the length of a pulse on a digital input (ie - how long the pin stayed high)
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
pulseStart <- 0; | |
function state_change() | |
{ | |
if (hardware.pin1.read()) | |
{ | |
pulseStart = hardware.micros(); | |
} | |
else | |
{ | |
server.log("Pulse on pin1 lasted " + (hardware.micros() - pulseStart) + " microseconds"); | |
} | |
} | |
hardware.pin1.configure(DIGITAL_IN, state_change); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment