-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
93 lines (73 loc) · 1.79 KB
/
index.js
File metadata and controls
93 lines (73 loc) · 1.79 KB
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
var five = require("johnny-five");
var board = new five.Board({
debug:false, repl: false
});
board.on("ready", function() {
/**
* In order to use the Stepper class, your board must be flashed with
* either of the following:
*
* - AdvancedFirmata https://github.com/soundanalogous/AdvancedFirmata
* - ConfigurableFirmata https://github.com/firmata/arduino/releases/tag/v2.6.2
*
*/
var stepper = new five.Stepper({
type: five.Stepper.TYPE.DRIVER,
stepsPerRev: 3200,
pins: [13, 12]
});
var pin = new five.Pin(11);
var photoSensor = new five.Pin('A0');
var toggleSwitch = new five.Switch(11);
var ac = new five.Pin(5);
var acPolarity = new five.Pin(6);
// toggleSwitch.on("close", function() {
// console.log("closed");
// });
// toggleSwitch.on("open", function() {
// console.log("open");
// });
var led = new five.Led(10);
var k = 0;
var i =0;
var accDir = 0;
var accOn = 0;
var iCount = 0
function acc(){
if (iCount == 0){
acPolarity.low();
ac.high();
}
else if (iCount == 10){
acPolarity.high();
}
else if (iCount == 20){
ac.low();
}
else if (iCount == 3){
}
else if (iCount == 100){
iCount =-1;
}
iCount ++
}
setInterval(acc, 50);
setInterval(function(){ led.toggle(); }, 1000)
function go(){
i++;
pin.query(function(state) {
photoSensor.query(function(state2){
process.stdout.write("light state: " + state2.value + " switch state: " + state.value +" icount: "+iCount+" \r" );
if((state.value==0) && (state2.value > 900)){
stepper.ccw().step(128, function() {
setTimeout(go,100);
});
}
else {
setTimeout(go,100);
}
});
});
}
go();
});