Skip to content

Instantly share code, notes, and snippets.

@ruanyf
Created June 11, 2017 12:44
Show Gist options
  • Save ruanyf/15c79ffde8e34b197f6ab0d75d89846a to your computer and use it in GitHub Desktop.
Save ruanyf/15c79ffde8e34b197f6ab0d75d89846a to your computer and use it in GitHub Desktop.
A server with LED on Raspberry Pi
var server = require('server');
var { get } = server.router;
var rpio = require('rpio');
rpio.open(11, rpio.OUTPUT);
function blink() {
rpio.write(11, rpio.HIGH);
setTimeout(function ledoff() {
rpio.write(11, rpio.LOW);
}, 50);
}
server({ port: 8080 }, [
get('/' , ctx => {
console.log('a request is coming...');
blink();
}),
]);
console.log('server starts on 8080 port');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment