Skip to content

Instantly share code, notes, and snippets.

@cat-haines
Created January 19, 2013 19:25
Show Gist options
  • Save cat-haines/4574544 to your computer and use it in GitHub Desktop.
Save cat-haines/4574544 to your computer and use it in GitHub Desktop.
electric imp code to read a digital signal and react when it changes.
// Register with the server
imp.configure("button example", [], []);
// readButton function called every 100ms
function changeState()
{
local pinState = hardware.pin1.read();
if (pinState)
server.show("pressed");
else
server.show("not pressed");
}
// set pin1 as a digital input with a pullup resistor and call changeState when the stateChanges
hardware.pin1.configure(DIGITAL_IN_PULLUP, changeState);
changeState();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment