You are reading a single comment by @fdufnews and its replies. Click here to read the full conversation.
  • Delay is not a good way to manage time dependant tasks as it uses all the resources for itself
    You can do it this way:

    var maxTime = 500;
    var maxStep = 10;
    var count = 0;
    var timer;
    var state = false;
    var blinkActive = false;
    
    function blink(){
      state = !state;
      digitalWrite(LED1,state);
      if (!state) count--;
      if (count===0){
        clearInterval(timer);
        blinkActive = false;
      }
    }
    
    function launchBlink(){
      if(blinkActive === false){
        count = maxStep;
        timer = setInterval(blink,maxTime);
        blinkActive = true;
      }
    }
    
    function onInit(){
      clearInterval();
      LED1.write(0);
      setWatch(launchBlink,BTN,{repeat: true, edge: 'rising', debounce: 100});
    }
    
    onInit();
    
About

Avatar for fdufnews @fdufnews started