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/1da28aaf1dbd537cb18f to your computer and use it in GitHub Desktop.
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.
// 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