Im currently trying to set the imp to only take a reading once every 4 seconds. At present it seems to be taking readings a few times every seconds. I have a contact sensor connected to pin1 and set to show high or low. I have looked over some previous worked examples but cant seem to find the correct way to write the code. Any help would be great.
Current Code:
local output = OutputPort(“Alarm”, “number”);
function sensor1() {
local sensor1state = hardware.pin1.read();
server.show(“1,” + sensor1state);
server.log(“1,” + sensor1state);
output.set(“1,” + sensor1state);
imp.sleep(4.0);
}
hardware.pin1.configure(DIGITAL_IN, sensor1);
server.log(“Hardware Configured”);
imp.configure(“Sensor Test”, [], [output]);