-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.snippet
executable file
·114 lines (95 loc) · 2.62 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
###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 [email protected]:semu/noduino.git
$ > cd noduino
$ > git submodule update --init
$ > npm install
$ > node app.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();
});
});
###arduinoMotion
int pirPin = 2; //digital 2
int ledPin = 13;
boolean hasCalibrated = false;
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop(){
if (hasCalibrated == false) {
Serial.println("calibrating");
hasCalibrated = true;
delay(2000);
}
int pirVal = digitalRead(pirPin);
if(pirVal == HIGH){ //was motion detected
Serial.println("MOTION");
digitalWrite(ledPin,HIGH);
delay(500);
} else {
Serial.println("Zzzz");
digitalWrite(ledPin,LOW);
delay(500);
}
}
###basicLEDNoduino
var Noduino = new NoduinoObj({debug: false, host: 'http://localhost:8090'}, Connector, Logger);
Noduino.connect(function(err, board) {
board.withLED({pin: 13}, function(err, LED) {
LED.blink(250);
LED.on('on', function() {
console.log('LED is on!');
});
});
});
###basicLEDJohnny
var five = require("johnny-five"),
board = new five.Board();
board.on("ready", function() {
var led = new five.Led(13);
var pir = new five.Pir({"pin": 2});
pir.on("calibrated", function() {
console.log( "calibrated" );
});
pir.on("motionstart", function() {
console.log( "MOTION" );
led.strobe();
});
pir.on("motionend", function() {
console.log( "Zzzz" );
led.stop();
});
});