Skip to content

Instantly share code, notes, and snippets.

@ebadawy
Created August 11, 2015 23:04
Show Gist options
  • Save ebadawy/20aee5d25c75b7b30a07 to your computer and use it in GitHub Desktop.
Save ebadawy/20aee5d25c75b7b30a07 to your computer and use it in GitHub Desktop.
Blinking onboard LED
<h2>Build and execute instructions</h2>
<img align="right" src="/static/images/black-usr3-led.PNG">
<ul>
<li>Run the example code and observe USR3 blinking.</li>
<li>Alter the frequency and re-run the example.</li>
</ul>
var b = require('bonescript');
var led = "USR3";
var state = 0;
b.pinMode(led, 'out');
toggleLED = function() {
state = state ? 0 : 1;
b.digitalWrite(led, state);
};
timer = setInterval(toggleLED, 100);
stopTimer = function() {
clearInterval(timer);
};
setTimeout(stopTimer, 3000);
<h2>See also</h2>
<h3>Topics</h3>
<ul>
<li><a href="/Support/BoneScript/#headers">BeagleBone expansion headers</a></li>
<li><a href="/Support/BoneScript/#digitalio">Digital I/O</a></li>
<li><a href="/Support/BoneScript/#timers">Timers</a></li>
</ul>
<h3>Related functions</h3>
<ul>
<li><a href="/Support/BoneScript/#require">require</a></li>
<li><a href="/Support/BoneScript/pinMode">pinMode</a></li>
<li><a href="/Support/BoneScript/digitalWrite">digitalWrite</a></li>
</ul>
<h3>Examples</h3>
<ul>
<li><a href="/Support/BoneScript/demo_blinkled_external">Blink an external LED</a></li>
</ul>
{"title":"Blink an LED","description":"Blinking onboard LED","bonecards":[{"title":"Build And Execute","type":"html"},{"title":"Demo","type":"code"},{"title":"See Also","type":"html"}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment