forked from jadonk/cloud9-examples
-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathswipeLED.js
executable file
·43 lines (38 loc) · 1012 Bytes
/
swipeLED.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env node
////////////////////////////////////////
// swipeLED.js
// Blinks the USR LEDs in sequence.
// Wiring:
// Setup:
// See:
////////////////////////////////////////
const fs = require('fs');
const leds = ['/sys/class/leds/beaglebone:green:usr0/brightness',
'/sys/class/leds/beaglebone:green:usr1/brightness',
'/sys/class/leds/beaglebone:green:usr2/brightness',
'/sys/class/leds/beaglebone:green:usr3/brightness'];
var i = 0;
const delay = 100;
console.log('Hit ^C to stop');
console.log("Toggling LEDs:");
ledOn();
function ledOn() {
process.stdout.write("\x1b[" + (n(i)+1) + "G1");
fs.writeFileSync(leds[n(i)], 1);
setTimeout(ledOff, delay);
}
function ledOff() {
process.stdout.write("\x1b[" + (n(i)+1) + "G0");
fs.writeFileSync(leds[n(i)], 0);
i++;
if(i >= 2*leds.length-2)
i = 0;
//i++; if(i > 3) i = 0;
ledOn();
}
function n(i) {
if(i >= leds.length)
return 2*leds.length-i-2;
else
return i;
}