forked from sbstjn/noduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.snippet
50 lines (41 loc) · 1.31 KB
/
examples.snippet
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
###basics
$ > ls /dev | grep usb
crw-rw-rw- 1 root wheel 18, 17 24 Feb 22:54 cu.usbmodem1d11
crw-rw-rw- 1 root wheel 18, 16 24 Feb 22:00 tty.usbmodem1d11
###node
$ > git clone git://github.com/semu/noduino.git
$ > cd noduino
$ > git submodule update --init
$ > npm install
$ > node srv.web.js
Listening on http://localhost:8080
###connect
var Noduino = new NoduinoObj({debug: true, host: 'http://localhost:8090'}, Connector);
Noduino.connect(function(err, board) {
if (err) { return console.log(err); }
console.log('Connected to board');
});
###toggleLED
var Noduino = new NoduinoObj({debug: true, host: 'http://localhost:8090'}, Connector);
Noduino.connect(function(err, board) {
if (err) { return console.log(err); }
board.withLED({pin: 13}, function(err, LED) {
if (err) { return console.log(err); }
LED.blink(250);
LED.on('on', function() {
console.log('LED is on!');
});
});
});
###listenButton
var Noduino = new NoduinoObj({debug: true, host: 'http://localhost:8090'}, Connector);
Noduino.connect(function(err, board) {
if (err) { return console.log(err); }
board.withButton({pin: 13}, function(err, Button) {
if (err) { return console.log(err); }
Button.on('push', function() {
console.log('Button pushed');
});
Button.push();
});
});