Skip to content

Instantly share code, notes, and snippets.

@dorantor
Created February 2, 2014 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dorantor/9be4206404f69683c203 to your computer and use it in GitHub Desktop.
Save dorantor/9be4206404f69683c203 to your computer and use it in GitHub Desktop.
First program for Espruino.
Bool = function (v) {
if (v) {
return true;
}
return false;
};
doCount = function (count) {
if (count < positions_amount) {
return count+1;
}
return 0;
};
updateLeds = function (count) {
LED1.write(
Bool(positions[count] & leds.LED1)
);
LED2.write(
Bool(positions[count] & leds.LED2)
);
LED3.write(
Bool(positions[count] & leds.LED3)
);
};
var leds = {
LED1: 1,
LED2: 2,
LED3: 4
};
var positions = [4,2,1,0,1,2,4,0,4,6,7,3,1,0,1,3,7,6,4,0,5,2,2,2,5,0];
var positions_amount = 26;
var count = 0;
function main() {
count = doCount(count);
updateLeds(count);
}
function onInit() {
clearInterval();
setInterval(main, 100);
}
function buttonWatcher(e) {
onInit();
console.log('pressed');
}
setWatch(buttonWatcher, BTN1, {edge:"falling", repeat:true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment