Last active
August 29, 2015 14:15
-
-
Save ElectricImpSampleCode/1da28aaf1dbd537cb18f to your computer and use it in GitHub Desktop.
Example code to sample a potentiometer connected to an imp. It makes use of the imp’s ANALOG_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 pin 2 as pot | |
pot <- hardware.pin2; | |
// Configure the pin for analog input | |
pot.configure(ANALOG_IN); | |
// Define a function to poll the pin every 0.1 seconds | |
function poll() { | |
// Read the pin and log its value | |
server.log(pot.read()); | |
// Wake up in 0.1 seconds and do it again | |
imp.wakeup(0.1, poll); | |
} | |
// Start the loop by calling the poll() function | |
poll(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment