-
Notifications
You must be signed in to change notification settings - Fork 0
/
kek.js
57 lines (42 loc) · 1.34 KB
/
kek.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
57
const piblaster = require('pi-servo-blaster.js');
const angleToPercent = angle => Math.floor((angle / 180) * 100);
let currentAngle = 0;
var Sound = require('aplay');
const move = amount => {
let newAngle = currentAngle + amount;
let response = 'OK';
if (newAngle > 180) {
newAngle = 180;
response = 'MAX LEFT';
}
if (newAngle < 0) {
newAngle = 0;
response = 'MAX RIGHT';
}
currentAngle = newAngle;
piblaster.setServoPwm("P1-13", angleToPercent(currentAngle) + "%");
/* console.log("Setting at: ", currentAngle, angleToPercent(currentAngle)); */
return response;
};
return (module.exports = {
left() {
return(move(10));
//return 'OK LEFT';
},
right() {
return(move(-10));
//return 'OK RIGHT';
},
shoot() {
new Sound().play('voice1.wav');
piblaster.setServoPwm("P1-11", angleToPercent(180) + "%");
piblaster.setServoPwm("P1-12", angleToPercent(90) + "%");
piblaster.setServoPwm("P1-11", angleToPercent(90) + "%");
piblaster.setServoPwm("P1-12", angleToPercent(180) + "%");
setTimeout(() => {
piblaster.setServoPwm("P1-11", angleToPercent(180) + "%");
piblaster.setServoPwm("P1-12", angleToPercent(90) + "%");
}, 900);
return 'OK SHOOT';
},
});