Skip to content

Instantly share code, notes, and snippets.

@electricimp
Last active December 19, 2015 00:29
Show Gist options
  • Save electricimp/5869373 to your computer and use it in GitHub Desktop.
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)
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