Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cat-haines/4574627 to your computer and use it in GitHub Desktop.
Save cat-haines/4574627 to your computer and use it in GitHub Desktop.
electric imp code to read a button, and send it to an output signal (to be processed in another node).
// readButton function called every 100ms
function changeState()
{
local buttonState = hardware.pin1.read();
buttonOutput.set(buttonState)
}
// set pin1 as a digital input with a pullup resistor and call changeState when the stateChanges
hardware.pin1.configure(DIGITAL_IN_PULLUP, changeState);
// Set Input/Output Ports
local buttonOutput = OutputPort(); // Create the port
// Register with the server (this time, we add buttonOutput to the array of output ports)
imp.configure("Read Button", [], [buttonOutput]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment