Created
October 24, 2017 22:52
-
-
Save scheib/f379c01844c1e06e73f9dafeb69c2d1d to your computer and use it in GitHub Desktop.
puck.js program to blink lights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment