-
Notifications
You must be signed in to change notification settings - Fork 0
/
LED_Server.js
67 lines (46 loc) · 1.12 KB
/
LED_Server.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var five = require( 'johnny-five' ),
board,
narf = require( 'narf' );
board = new five.Board();
/*
Executes a command and fires event when done that
will return the command output
*/
// The board's pins will not be accessible until
// the board has reported that it is ready
board.on("ready", function() {
var val = 0;
// Set pin 13 to OUTPUT mode
this.pinMode( 13, 1 );
// Mode Table
// INPUT: 0
// OUTPUT: 1
// ANALOG: 2
// PWM: 3
// SERVO: 4
this.digitalWrite( 13, 0 );
/* Api functions */
var self = this;
var APIFunctions = {
GET : {
ledSwitch : function ( data, callback ){
data.url.value = parseInt( data.url.value, 0 );
if( data.url.value === 1 || data.url.value === 0){
self.digitalWrite( 13, data.url.value );
}
callback( data.url.value );
}
},
POST : {}
};
console.log( narf );
var hs = new narf.HttpServer( { port : 8080 } ).start();
hs.on( 'port', function( port ){
hs.addAPI( { functions : APIFunctions } );
} );
});
narf.setDebug( false );
narf.pageServer( {
port : 8079,
path : __dirname + '/'
} );