Last active
August 29, 2015 14:15
-
-
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.
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
// 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