-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroverSoundSensor.js
56 lines (45 loc) · 1.31 KB
/
roverSoundSensor.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
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var mic = new five.Sensor("A0");
// Johnny-Five provides pre-packages shield configurations!
// http://johnny-five.io/api/motor/#pre-packaged-shield-configs
var motors = new five.Motors([
five.Motor.SHIELD_CONFIGS.POLOLU_DRV8835_SHIELD.M1,
five.Motor.SHIELD_CONFIGS.POLOLU_DRV8835_SHIELD.M2,
]);
this.repl.inject({
motors: motors
});
var running = 1;
var dir = 1;
mic.on("data", function(sound) {
// console.log(this.value );
if ( this.value > 200 ) {
// motors.stop();
// running = 0;
motors[0].speed(50).rev();
// motors[1].speed(50).rev();
setTimeout(function(){
motors[0].speed(50).fwd();
running = 1;
}, 1000);
}
// else if( this.value < 100 && running === 0 ){
// motors[0].speed(50).rev();
// // motors[1].speed(50).rev();
// setTimeout(function(){
// motors[0].speed(50).fwd();
// running = 1;
// }, 1000);
// // if (dir === 1) {
// // motors[0].speed(50).fwd();
// // motors[0].speed(50).fwd();
// // dir = -1;
// // } else else{
// // motors.speed(50).rev();
// // dir = 1;
// // }
// }
});
});