-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbq.ino
80 lines (63 loc) · 1.43 KB
/
bbq.ino
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
#include "max6675.h"
#include <AFMotor.h>
int thermoDO = 5;
int thermoCS = 6;
int thermoCLK = 9;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
AF_DCMotor motor(1, MOTOR12_1KHZ);
void setup() {
Serial.begin(9600);
motor.setSpeed(255);
delay(1000);
startMotor();
}
void loop() {
double currentTemp = thermocouple.readCelsius();
beforeChangeMotor(currentTemp);
if(isAtCookingTemperature(currentTemp)) {
stopMotor();
} else if (isCold(currentTemp)) {
highOxygen();
} else if(isWarm(currentTemp)) {
heat();
}
delay(1000);
}
int secondsRunning = 0;
int secondsToWait = 0;
void heat() {
if(secondsRunning > 20) {
stopMotor();
secondsRunning = 0;
secondsToWait = 120;
} else if(secondsToWait <= 0) {
startMotor();
secondsRunning++;
} else {
secondsToWait--;
}
}
void highOxygen() {
startMotor();
}
void startMotor() {
motor.run(BACKWARD);
}
void stopMotor() {
motor.run(RELEASE);
}
const double WARM_FIRE_TEMPERATURE = 70;
const double COOKING_TEMPERATURE = 110;
bool isCold(double temperature) {
return temperature <= WARM_FIRE_TEMPERATURE;
}
bool isWarm(double temperature) {
return temperature < COOKING_TEMPERATURE && temperature > WARM_FIRE_TEMPERATURE;
}
bool isAtCookingTemperature(double temperature) {
return temperature >= COOKING_TEMPERATURE;
}
void beforeChangeMotor(double temperature) {
Serial.print("C = ");
Serial.println(temperature);
}