-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStandaloneBurner.ino
205 lines (153 loc) · 4.74 KB
/
StandaloneBurner.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <FiniteStateMachine.h>
State Off = State(enterOff, updateOff, exitOff); // burner is off
State Lighting = State(enterLighting, updateLighting, exitLighting); // burner is trying to light
State On = State(enterOn, updateOn, exitOn); // burner is on
State Alarm = State(updateAlarm); //burner failed to light or went out
FSM Burner = FSM(Off); // start finite state machine in the Off state
#define GasRelayPin 3
#define IgniterRelayPin 2
#define CommandPin 4
#define StatusPin 5
#define OffStatusLedPin 9
#define LightingStatusLedPin 10
#define OnStatusLedPin 8
#define FlameSensorPin 6
#define BuzzerPin 7
#define RelayOn 1
#define RelayOff 0
#define LedOn 1
#define LedOff 0
#define CommandOn 0
#define CommandOff 1
#define StatusOn 0
#define StatusOff 1
#define FlameOn 0
#define FlameOff 1
#define FlameWaitTime 3000 // wait 2 sec for flame
#define GasClearTime 4000 // 10 sec for gas to dissipate
#define NumLightingTries 3
#define BuzzerOn 0
#define BuzzerOff 1
int BurnerTries = 1; // counts tries to light Burner
void setup()
{
pinMode(GasRelayPin,OUTPUT);
digitalWrite(GasRelayPin,RelayOff);
pinMode(IgniterRelayPin,OUTPUT);
digitalWrite(IgniterRelayPin,RelayOff);
pinMode(CommandPin,INPUT_PULLUP); // off unless pulled low by brewery controller
pinMode(StatusPin,OUTPUT);
pinMode(OffStatusLedPin,OUTPUT);
pinMode(LightingStatusLedPin,OUTPUT);
pinMode(OnStatusLedPin,OUTPUT);
pinMode(FlameSensorPin,INPUT_PULLUP);
pinMode(BuzzerPin,OUTPUT);
digitalWrite(BuzzerPin,BuzzerOff);
} // end setup()
void loop()
{
Burner.update();
} // end loop()
void enterOff()
{
digitalWrite(StatusPin,StatusOff);
digitalWrite(GasRelayPin,RelayOff);
digitalWrite(IgniterRelayPin,RelayOff);
digitalWrite(OffStatusLedPin,LedOn);
digitalWrite(LightingStatusLedPin,LedOff);
digitalWrite(OnStatusLedPin,LedOff);
} // end enterOff()
void updateOff()
{
if(digitalRead(CommandPin) == CommandOn)
Burner.transitionTo(Lighting);
} // end updateOff()
void exitOff()
{
BurnerTries = 1;
}
void enterLighting()
{
digitalWrite(OffStatusLedPin,LedOff);
digitalWrite(LightingStatusLedPin,LedOn);
digitalWrite(OnStatusLedPin,LedOff);
} // end enterLighting()
void updateLighting()
{
if(BurnerTries > NumLightingTries)
{ // we are done trying!
digitalWrite(GasRelayPin,RelayOff);
digitalWrite(IgniterRelayPin,RelayOff);
Burner.transitionTo(Alarm);
}
else // we are still trying!
{
BurnerTries = BurnerTries + 1;
digitalWrite(IgniterRelayPin,RelayOn); // try starting
digitalWrite(GasRelayPin,RelayOn);
unsigned long endtime = millis()+ FlameWaitTime;
while(digitalRead(FlameSensorPin) != FlameOn && millis()< endtime)
{
if(digitalRead(CommandPin) == CommandOff)
Burner.transitionTo(Off);
} // end while
if(digitalRead(FlameSensorPin) == FlameOn)
{
digitalWrite(IgniterRelayPin,RelayOff);
Burner.transitionTo(On);
}
if(digitalRead(FlameSensorPin) == FlameOff)
{ // allow time for gas to clear before trying again
unsigned long endtime = millis() + GasClearTime;
digitalWrite(GasRelayPin,RelayOff);
digitalWrite(IgniterRelayPin,RelayOff);
while(millis() < endtime)
{
if(digitalRead(CommandPin) == CommandOff)
Burner.transitionTo(Off);
} // end while(millis() < endtime)
} // end if(digitalRead(FlameSensorPin) == FlameOff)
} // end else of if(BurnerTries > NumLightingTries)
} // end updateLighting()
void exitLighting()
{
}
void enterOn()
{
digitalWrite(StatusPin,StatusOn);
digitalWrite(OnStatusLedPin,LedOn);
digitalWrite(LightingStatusLedPin,LedOff);
digitalWrite(OffStatusLedPin,LedOff);
} // end enterOn()
void updateOn()
{
if(digitalRead(FlameSensorPin) == FlameOff)
Burner.transitionTo(Alarm);
if(digitalRead(CommandPin) == CommandOff)
Burner.transitionTo(Off);
digitalWrite(OnStatusLedPin,LedOff);
delay(300);
digitalWrite(OnStatusLedPin,LedOn);
delay(300);
} // end updateOn()
void exitOn()
{
} // end exitOn()
void updateAlarm()
{ //we be beepin' and a flashin'
digitalWrite(GasRelayPin,RelayOff);
digitalWrite(IgniterRelayPin,RelayOff);
digitalWrite(BuzzerPin,BuzzerOn);
digitalWrite(OffStatusLedPin,LedOn);
digitalWrite(LightingStatusLedPin,LedOn);
digitalWrite(OnStatusLedPin,LedOn);
delay(500);
digitalWrite(BuzzerPin,BuzzerOff);
digitalWrite(OffStatusLedPin,LedOff);
digitalWrite(LightingStatusLedPin,LedOff);
digitalWrite(OnStatusLedPin,LedOff);
delay(500);
// brewery controller must set Command to Off to cancel Alarm Mode
if(digitalRead(CommandPin) == CommandOff)
Burner.transitionTo(Off);
} //end updateAlarm()