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