Created
January 19, 2013 20:59
-
-
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.
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
// 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