-
Notifications
You must be signed in to change notification settings - Fork 2
/
CoffeePID.js
76 lines (56 loc) · 1.98 KB
/
CoffeePID.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var greenBean = require("green-bean");
var prompt = require('prompt');
prompt.start();
var period = 10000 //This is the period for one ON/OFF cycle of the element.
var element = 11; // 11 = Bake, 12 = Broil, 48 = Convect
var power = 0;
var promptPID = 0;
var PID = 0.01 * promptPID;
var OnTime = PID * period;
//var OffTime = period - OnTime;
var getInputs = function (power, element) {
prompt.get(['power', 'element'], function (err, result) {
if(result.power == 'exit') {
range.fctMode.write(0); // exit fct mode
} else {
promptPID = parseInt(result.power);
element = parseInt(result.element)
console.log(' Power (0 to 100): ' + promptPID);
console.log(' Element (bake = 11, broil = 12, convect = 48): ' + element);
PID = 0.01 * promptPID;
OnTime = PID * period;
getInputs(power, element);
}
});
};
greenBean.connect("range", function(range) {
range.fctMode.write(1); // enter fct mode
range.ovenLight.write(1); // turn on oven light
setInterval(function() {
range.fctMode.write(1); // stay in fct mode
}, 15000);
getInputs(power, element);
/*
range.elementStatus.subscribe(function(value) {
console.log("element status changed:", value);
});
*/
range.convectionFan.write({
upperOvenConvectionFanDrivePercentage: 0,
upperOvenConvectionFanRotation: 0,
lowerOvenConvectionFanDrivePercentage: 100,
lowerOvenConvectionFanRotation: 0
});
setInterval(function() {
range.elementStatus.write({
upperOvenElementStatus: 0,
lowerOvenElementStatus: element
});
setTimeout(function() {
range.elementStatus.write({
upperOvenElementStatus: 0,
lowerOvenElementStatus: 0
});
},OnTime);
},period);
});