-
Notifications
You must be signed in to change notification settings - Fork 1
/
tst.js
52 lines (37 loc) · 1.15 KB
/
tst.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
var Board = require('node-arduino')
, board = new Board.connect('/dev/tty.usbmodem1421')
;
board.sp.open(function (error) {
if ( error ) {
console.log('failed to open: '+error);
} else {
console.log('open');
setTimeout(function () {
board.pinMode(13, board.OUTPUT, board.HIGH);
board.pinModeSetDefault(22, board.OUTPUT, board.HIGH);
var val = 50;
setInterval(function () {
if (val > 200) {
val = 0;
}
val+= 50;
//console.log(val);/
board.analogWrite(13, val);
//board.analogReadAverage(0, 5000, function(v) {
// console.log('read',v)
//}) ;
board.analogRead(0, function(v) {
console.log('read0',v)
}) ;
//_toggleLight();
}, 500);
}, 1000);
}
});
function _toggleLight() {
console.log('toggleLight pin: ', 22);
board.digitalWrite(22, board.LOW);
setTimeout(() => {
board.digitalWrite(22, board.HIGH);
}, 250);
}