Created
October 4, 2013 19:21
-
-
Save johnvilsack/6831252 to your computer and use it in GitHub Desktop.
Pre-JSON script for LED toggling
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
var bone = require('bonescript'); | |
var state = bone.LOW; | |
bone.pinMode("USR0", bone.OUTPUT); | |
bone.pinMode("USR1", bone.OUTPUT); | |
bone.pinMode("USR2", bone.OUTPUT); | |
bone.pinMode("USR3", bone.OUTPUT); | |
setInterval(toggle, 10); | |
function toggle() { | |
var chanceUSR0 = Math.floor(Math.random()*100); | |
var chanceUSR1 = Math.floor(Math.random()*100); | |
var chanceUSR2 = Math.floor(Math.random()*100); | |
var chanceUSR3 = Math.floor(Math.random()*100); | |
if (chanceUSR0 > 90) { | |
if(state == bone.LOW) state = bone.HIGH; | |
else state = bone.LOW; | |
bone.digitalWrite("USR0", state); | |
} | |
if(chanceUSR1 > 90) { | |
if(state == bone.LOW) state = bone.HIGH; | |
else state = bone.LOW; | |
bone.digitalWrite("USR1", state); | |
} | |
if(chanceUSR2 > 90) { | |
if(state == bone.LOW) state = bone.HIGH; | |
else state = bone.LOW; | |
bone.digitalWrite("USR2", state); | |
} | |
if(chanceUSR3 > 90) { | |
if(state == bone.LOW) state = bone.HIGH; | |
else state = bone.LOW; | |
bone.digitalWrite("USR3", state); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment