Skip to content

Instantly share code, notes, and snippets.

@cat-haines
Created January 19, 2013 20:59
Show Gist options
  • Save cat-haines/4575100 to your computer and use it in GitHub Desktop.
Save cat-haines/4575100 to your computer and use it in GitHub Desktop.
This example reads the value of an analog sensor hooked up to pin 2, and writes it to the server whenever the button is pressed.
// Register with the server
imp.configure("Press button to read", [], []);
// readButton function called every 100ms
function changeState()
{
local pinState = hardware.pin1.read();
if (pinState)
{
local sensorValue = hardware.pin2.read();
server.show(sensorValue);
}
}
// set pin1 as a digital input with a pullup resistor and call changeState when the stateChanges
hardware.pin1.configure(DIGITAL_IN_PULLUP, changeState);
hardware.pin2.configure(ANALOG_IN);
changeState();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment