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/cc70d04d292e55aeb826 to your computer and use it in GitHub Desktop.
Save ElectricImpSampleCode/cc70d04d292e55aeb826 to your computer and use it in GitHub Desktop.
Example code to blink an LED connected to an imp. It makes use of the imp’s DIGITAL_OUT GPIO pin setting.
// Assign pin9 to a global variable
led <- hardware.pin9;
// Configure LED pin for DIGITAL_OUTPUT, and set initial state to off
led.configure(DIGITAL_OUT, 0);
// Assign a global variable to track current state of LED pin
state <- 0;
// Function to blink LED
function blink() {
// Flip the state variable: 1 -> 0, 0 -> 1
state = (state == 1) ? 0 : 1;
// Set LED pin to new value
led.write(state);
// Schedule the blink function to run again in .5 seconds
imp.wakeup(0.5, blink);
}
// Initial call to the blink function to begin looping
blink();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment