You are reading a single comment by @mgg1010 and its replies. Click here to read the full conversation.
  • Hi

    I'm using setWatch on an input that has 50hz pulses which are ~0.9ms wide. I was expecting to see two callbacks alternating true/false per pulse, one for each edge - but I actually see multiple successive true or false values. This seems strange.

    My code

    '''
    var states=new Array();
    var index=0;

    function onpulse(e)
    {
    states.push(e);
    if (index<100) index++;
    }

    setWatch(onpulse,C5,{repeat:true,edge:'both',debounce:0});
    '''

    I'm storing the state change data in an array to try to be sure I'm catching
    all the events - I thought that printing them might cause some to be lost.

    The output I get looks like this

    '''

    for(var i=0;i<100;i++) {print(states[i]);}
    {"lastTime":undefined,"time":41004.582653045654296875,"state":false}
    {"lastTime":41004.582653045654296875,"time":41004.5826625823974609375,"state":false}
    {"lastTime":41004.5826625823974609375,"time":41004.588489532470703125,"state":false}
    {"lastTime":41004.588489532470703125,"time":41004.588512420654296875,"state":true}
    {"lastTime":41004.588512420654296875,"time":41004.58955669403076171875,"state":false}
    {"lastTime":41004.58955669403076171875,"time":41004.60842227935791015625,"state":false}
    {"lastTime":41004.60842227935791015625,"time":41004.60844326019287109375,"state":true}
    {"lastTime":41004.60844326019287109375,"time":41004.60946750640869140625,"state":false}
    {"lastTime":41004.60946750640869140625,"time":41004.62811374664306640625,"state":false}
    {"lastTime":41004.62811374664306640625,"time":41004.62813091278076171875,"state":true}
    {"lastTime":41004.62813091278076171875,"time":41004.62916660308837890625,"state":false}
    {"lastTime":41004.62916660308837890625,"time":41004.647785186767578125,"state":false}
    {"lastTime":41004.647785186767578125,"time":41004.64781093597412109375,"state":true}
    {"lastTime":41004.64781093597412109375,"time":41004.64885044097900390625,"state":false}
    {"lastTime":41004.64885044097900390625,"time":41004.6675014495849609375,"state":false}
    {"lastTime":41004.6675014495849609375,"time":41004.66751956939697265625,"state":true}
    {"lastTime":41004.66751956939697265625,"time":41004.66753864288330078125,"state":true}
    '''

    What's puzzling me is that there doesn't seem to be any pattern - I was
    expecting true,false, true, false...

    Any ideas?

    Martin

About

Avatar for mgg1010 @mgg1010 started