Skip to content

Instantly share code, notes, and snippets.

@bennycode
Created October 1, 2017 18:20
Show Gist options
  • Save bennycode/e02c354e5e2ac7a4333c01f006a423a1 to your computer and use it in GitHub Desktop.
Save bennycode/e02c354e5e2ac7a4333c01f006a423a1 to your computer and use it in GitHub Desktop.
Blinking LEDs example (BeagleBone Black Wireless)
#!/usr/bin/env node
'use strict';
const b = require('bonescript');
console.log('VERSION', 2);
console.log(`Working directory of the Node.js process: ${process.cwd()}`);
const leds = ['USR0', 'USR1', 'USR2', 'USR3', 'P9_14'];
// Prepare LEDs
for (const led of leds) {
b.pinMode(led, b.OUTPUT);
}
function lightOn(turnOn) {
const state = (turnOn) ? b.HIGH : b.LOW;
for (const led of leds) {
b.digitalWrite(led, state);
}
}
function toggleLEDs() {
let turnOn = false;
setInterval(() => {
lightOn(turnOn);
turnOn ^= true;
}, 1000);
}
toggleLEDs();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment