-
Notifications
You must be signed in to change notification settings - Fork 1
/
hardware.js
48 lines (40 loc) · 1.03 KB
/
hardware.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
var piblaster = require("pi-blaster.js");
// servo wiring colours: brown negative, red positive, orange signal
var hardware = {
candy:{},
servo:{
servo_pin: 4,
// 0.2 is far left
// 0.15 is center
// 0.1 is far right
closedAngle: 0.184,
openAngle: 0.1,
open: function(){
console.log('open');
piblaster.setPwm(servo_pin, this.openAngle);
},
close: function(){
console.log("close");
piblaster.setPwm(servo_pin, this.closedAngle);
}
}
};
console.info('start hardware');
hardware.candy.dispense = function(){
console.log('dispense Candy');
hardware.servo.open();
setTimeout(function(){
hardware.servo.close();
}, 300);
};
hardware.candy.open = function(){
console.log('open Candy wide');
hardware.servo.openAngle -= 0.02;
hardware.servo.open();
hardware.servo.openAngle += 0.02;
};
hardware.candy.close = function(){
console.log('close Candy');
hardware.servo.close();
};
module.exports = hardware.candy;