• I was wondering how to code given behaviour:
    increment counter when button is pressed
    keep incrementing when button is held down

    such a behaviour is often implemented for setting hours etc.

    I've tried this:

    var presses=0;
    //presses count
    pinMode(A7, "input_pulldown");
    // software pulldown
    
    setWatch(function(){
      clearInterval();
      presses++;
      setInterval(function(){
        if(digitalRead(A7)) {
          presses++;
          console.log(presses);
        } else {clearInterval();}
      }, 500);
      console.log(presses);
    },A7,{ repeat : true, debounce : 30, edge : "rising" }  );
    

    It works... but it's clearing other intervals.
    Is there a cleaner/better way to code this?
    If you know how to code it better, or have your own solution please share

    Thanks

About

Avatar for ancienthero @ancienthero started