Seems to be the exact same issue; here is my implementation:
`//////MAIN//////////
imp.setpowersave(true);
imp1state <- 0;
imp2state <- 0;
imp3state <- 0;
led9 <- hardware.pin9;
led8 <- hardware.pin7;
led7 <- hardware.pin5;
led9.configure(PWM_OUT, 0.02, 0.0);
led8.configure(PWM_OUT, 0.02, 0.0)
led7.configure(PWM_OUT, 0.02, 0.0);
values <- 0;
changes <- 1;
imp.configure(“touchstone1”, [], []);
// assign hardware.pin9 to a variable to make things more clear
button <- hardware.pin2;
function poll()
{
local state = button.read();
values += changes;
// Change direction when we get to the end
if (values == 100) {
changes = -1;
}
led8.write(values/256.0);
// Only call back if values isn’t zero; as we enter first time with values=0 and changes=1, by the time we get here values=1 and won’t get back to zero until we go all the way to 100 and back again
//if (values != 0) imp.wakeup(0.01, poll);
if (button.read()==1) imp.wakeup(0.01, poll);
}
/*
function buttonStateChanged() {
// read the current state
//local state = button.read();
server.log(imp1state);
send it to the agent
agent.send("touchstone1", state);
}
*/
function setLed(value) {
if (value ==2){
imp2state = 7;
}
else if (value==20){
imp2state=0;
}
if (value ==3){
imp3state = 8;
}
else if (value==30)
{
imp3state=0;
}
server.log("IMP 2 = "+ imp2state)
server.log("IMP 3 = "+ imp3state)
if (imp2state == 7 && imp3state==0) {
}
if(imp2state==0 && imp3state==0){
led9.write(0);
led8.write(0);
led7.write(0);
}
if (imp3state == 8 && imp2state==0) {
led9.write(1);
led8.write(0);
led7.write(1);
}
if(imp2state==7 && imp3state==8){
led9.write(1);
led8.write(0.01);
led7.write(1);
}
}
// setup a handler for setLed message from the agent
agent.on(“setLed”, setLed);
// configure the button
button.configure(DIGITAL_IN_PULLDOWN, poll);
`