-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added javascript version of LED blink
- Loading branch information
1 parent
4d0192b
commit 3fe907a
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// blink an LED with JavaScript. | ||
// | ||
// requires the following: | ||
// nodejs as a container to run in | ||
// should already be in the Raspbian image | ||
// npm to install the onoff library | ||
// sudo apt-get install npm | ||
// onoff to interface with the GPIO board | ||
// sudo npm install onoff | ||
|
||
// a simple and brute force sleep function that | ||
// Javascript does not have as a built-in. | ||
function sleep(delay) { | ||
var start = new Date().getTime(); | ||
while (new Date().getTime() < start + delay); | ||
} | ||
|
||
var Gpio = require('onoff').Gpio; | ||
var LED = new Gpio(17, 'out'); // use BCM pin numbering, not wiringPi | ||
|
||
// a loop to blink the LED 10 times. | ||
for (i=0; i < 10; i++) { | ||
LED.writeSync(0); | ||
sleep (1000); | ||
LED.writeSync(1); | ||
sleep (1000); | ||
} | ||
|
||
LED.unexport(); |