I’ve written a simple bit of code to take a button input to the imp. It sends the button value to the server, and outputs a count of the number if times it has been pressed.
I trigger the function whenChanged() when pin 8 sees a change of state
The variable ‘buttonCount’ should increase by 1 every time the button is pressed, but it’s going up by 2.
Any ideas?
`//Blue Button
local buttonState;
local buttonCount = 0;
local output = OutputPort(“Result”, “number”);
function whenChanged()
{
imp.sleep(0.05);
buttonState = hardware.pin8.read();
buttonState = buttonState?0:1;
if (buttonState){
buttonCount++;
}
server.show(buttonState);
output.set(buttonCount);
}