You are reading a single comment by @fobus and its replies. Click here to read the full conversation.
  • I have coded a class for this problem. Works great and stable for me. I'm sharing it.

    watchClass=function(pin,callback){
        var lastTime=0;
        lastState=1;
        var interval=setInterval(function(){
            currentState=digitalRead(pin);
            currentTime=getTime();
            if (currentState!=lastState) {
                var e={
                    state:currentState,
                    lastTime:lastTime,
                    time:currentTime
                }
                lastTime=currentTime;
                lastState=currentState;
                callback(e);
            }
        },30);
    }
    pinMode(E2, "input_pulldown");
    x=new watchClass(E2,function(e){
    console.log(e);
    });
    
About

Avatar for fobus @fobus started