You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • Below is the code as described in post #2. The cycle starts over again after display has completed. Display is a series of blinking green and red blinking:

    • green for every 10 seconds
    • red for every second remaining
    • very brief red flash for less then a second

      // puckD1extPushButton.js
      pinMode(D1,"input_pullup");
      var log = function() { console.log(arguments); }
      , lon = false // log on / off
      , blT = 200 // blinkTime (on and off time)
      , flT = 20 // flashTime (for less than a second pressed)
      , t0, t1
      , wIdD, wIdU
      , down = function() {
        if (wIdU) clearWatch(wIdU);
        wIdD = null;
        t0 = getTime();
        wIdU = setWatch(up,D1
                 ,{repeat:false, edge:"rising",debounce:10});
      }
      , up = function() {
        if (wIdD) clearWatch(wIdD);
        wIdU = null;
        t1 = getTime();
        setTimeout(show,10,Math.floor(t1 - t0));
      }
      , show = function(t) {
        if (lon) log(t);
        if (t>10) {
          LED2.set();
          setTimeout(function(){
            LED2.reset();
            setTimeout(show,blT,t-10);
          },blT);
        } else if (t>0) {
          LED1.set();
          setTimeout(function(){
            LED1.reset();
            if (--t>0) {
              setTimeout(show,blT,t);
            } else{
              start();
            }
          },blT);
        } else {
          LED1.set();
          setTimeout(function(){
            LED1.reset();
            setTimeout(start,blT);
          },flT);
        }
      }
      , start = function() {
          wIdD = setWatch(down,D1
                   ,{repeat:false, edge:"falling",debounce:10});
      }
      ;
      function onInit() {
      start();
      }
      
      setTimeout(onInit,999); // comment line before upload for save()
      

    With a pretty decent - not much bouncing switch - there should be a much simpler solution... except for the display, which then gets a bit more complicated: results would have to be written to a queue and display would run asynchronously / simultaneously. To distinguish between flash/blink sequences, blue led could be flashed between the sequences.

About

Avatar for allObjects @allObjects started