Last active
December 12, 2015 09:29
-
-
Save tcr/4752180 to your computer and use it in GitHub Desktop.
Source code for the Electric Imp GraphButton example.
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
// GraphButton source code | |
// Set output port for planner. | |
local output = OutputPort("trigger"); | |
// Callback when the button is pressed. | |
function pin7changed() { | |
local buttonState = hardware.pin7.read(); | |
// If buttonState is 0, the button is pushed. | |
if (buttonState == 0) { | |
hardware.pin8.write(0); | |
output.set("trigger"); | |
server.show("Button Pressed!"); | |
} else { | |
hardware.pin8.write(1); | |
server.show("Button Released!"); | |
} | |
} | |
// LEDs on pin 8 is active low, so writing the pin a 1 will turn the LED off. | |
hardware.pin8.configure(DIGITAL_OUT_OD_PULLUP); | |
hardware.pin8.write(1); | |
server.show("LEDs configured."); | |
// Pin 7 is a digital input (0 or 1) and is pulled up externally. | |
hardware.pin7.configure(DIGITAL_IN_PULLUP, pin7changed); | |
// Register with the server | |
imp.configure("GraphButton POSTer", [], [output]); | |
// Display our important message | |
server.show("GraphButton ready."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment