Skip to content

Instantly share code, notes, and snippets.

@ElectricImpSampleCode
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElectricImpSampleCode/98206052dee551b6c4f6 to your computer and use it in GitHub Desktop.
Save ElectricImpSampleCode/98206052dee551b6c4f6 to your computer and use it in GitHub Desktop.
Example code to sample a button connected to an imp. It makes use of the imp’s DIGITAL_IN GPIO pin setting.
// Alias the GPIO pin as 'button'
button <- hardware.pin1;
function buttonPress() {
local state = button.read();
if (state == 1) {
// The button is released
server.log("Release");
} else {
// The button is pressed
server.log("Press");
}
}
// Configure the button to call buttonPress() when the pin's state changes
button.configure(DIGITAL_IN_PULLUP, buttonPress);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment