Skip to content

Instantly share code, notes, and snippets.

@scheib
Created October 24, 2017 22:52
Show Gist options
  • Select an option

  • Save scheib/f379c01844c1e06e73f9dafeb69c2d1d to your computer and use it in GitHub Desktop.

Select an option

Save scheib/f379c01844c1e06e73f9dafeb69c2d1d to your computer and use it in GitHub Desktop.

Revisions

  1. scheib created this gist Oct 24, 2017.
    32 changes: 32 additions & 0 deletions puck-js-blinky-lights.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    function setLed(n) {
    LED1.write(n === 1);
    LED2.write(n === 2);
    LED3.write(n === 3);
    }

    function blinkCount(n) {
    if (n === 0) {
    n = 5;
    }

    var led = 0;
    var count = n;
    var interval = setInterval(function() {
    led = (led + 1) % 4;
    setLed(led);

    if (led === 0) {
    count -= 1;
    }

    if (count === 0) {
    clearInterval(interval);

    setTimeout(function() {
    blinkCount(n - 1);
    }, 1000);
    }
    }, 200);
    }

    blinkCount(0);