forked from mbroek/MBSE-ArdRims
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMBSE-ArdRims.ino
1615 lines (1436 loc) · 42.1 KB
/
MBSE-ArdRims.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==============================================
// ATTENTION!!!!!
// YOU MUST SET ONLY THIS SECTION
// ==============================================
#include <EEPROM.h>
#include <OneWire.h>
#include <PID_v1.h>
//SET PCB
// 1 Brauduino Original (Matho's PCB)
// 2 Brauduino by DanielXan
// 3 ArdBir by DanielXan
// 4 Protoduino NANO by J. Klinge
// 5 ArdRims NANO by C. Broek
// 6 ArduinoBrewboard by J. Klinge ?? 2 soorten ??
#define PCBType 5
// should be false
#define FakeHeating false // For development only.
#define USE_HLT false // A HLT shared with the MLT. (Not yet).
#define Silent false // No beeps (during development).
// Serial debugging
#define DebugPID false
#define DebugProcess false
#define DebugButton false
#define DebugReadWrite false
#define DebugErrors true
// Default language is English, others must be set.
// Nederlands.
#define langNL true
// Don not change this next block
#if FakeHeating == true
#define USE_DS18020 false
#else
#define USE_DS18020 true
#endif
#if USE_DS18020 == true
// Normal brew sensor
#if PCBType == 1
const byte SensorMLTPin = 11;
#elif PCBType == 2
const byte SensorMLTPin = 8;
#elif (PCBType == 3 || PCBType == 4 || PCBType == 6)
const byte SensorMLTPin = 7;
#elif PCBType == 5
const byte SensorMLTPin = 7;
#if USE_HLT == true
// Sensor for sparge water.
const byte SensorHLTPin = 11;
#endif // USE_HLT
#endif // PCBType
#endif // USE_DS18020
// Output Pump, Buzzer, Heater
#if PCBType == 1
#define PumpControlPin 8
#define BuzzControlPin 10
#define HeatControlPin 9
#elif PCBType == 2
#define PumpControlPin 9
#define BuzzControlPin 10
#define HeatControlPin 11
#elif PCBType == 3
#define PumpControlPin 6
#define BuzzControlPin 8
#define HeatControlPin 9
#elif PCBType == 4
#define PumpControlPin 6
#define BuzzControlPin A7
#define HeatControlPin 9
#elif PCBType == 5
#define PumpControlPin 6
#define BuzzControlPin 8
#define HeatControlPin 9
#if USE_HLT == true
// Heater for sparge water
#define HLTControlPin 10
#endif
#elif PCBType == 6
#define PumpControlPin 6
#define BuzzControlPin 11
#define HeatControlPin 9
#endif
// Keyboard buttons
#if (PCBType == 1 || PCBType == 5)
#define ButtonUpPin A3
#define ButtonDownPin A2
#define ButtonStartPin A1
#define ButtonEnterPin A0
#elif PCBType == 2
#define ButtonUpPin A3
#define ButtonDownPin A2
#define ButtonStartPin A0
#define ButtonEnterPin A1
#elif (PCBType == 3 || PCBType == 4 || PCBType == 6)
#define ButtonUpPin A2
#define ButtonDownPin A3
#define ButtonStartPin A0
#define ButtonEnterPin A1
#endif
#if USE_DS18020 == true
OneWire dsm(SensorMLTPin);
#if USE_HLT == true
OneWire dsh(SensorHLTPin);
#endif
#endif
// LCD connections
#include <LiquidCrystal.h>
#if (PCBType == 1 || PCBType == 2)
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
#elif (PCBType == 3 || PCBType == 4 || PCBType == 5)
LiquidCrystal lcd(A4, A5, 2, 3, 4, 5);
#elif (PCBType == 6)
LiquidCrystal lcd(A5, A4, 2, 3, 4, 5);
#endif
/*
Timer using the interrupt driven secTimer library.
*/
#include <secTimer.h>
secTimer myTimer;
// ==============================================
// END OF SETTING SECTION
// ==============================================
/*
MBSE-ArdRims is a single (well ..) vessel RIMS controller. It is
based on ideas of braudino, Open-ArdBir, BrewManiac and maybe others.
Most of the code is written from scratch.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// *************************
//* global variables
// *************************
#include "defines.h"
unsigned long gSystemStartTime; // in milliseconds.
unsigned long gCurrentTimeInMS; // in milliseconds.
unsigned long w_StartTime;
unsigned long Timer;
unsigned long _seconds; // timer seconds.
#if FakeHeating == true
unsigned long FakeHeatLastInMS; // in milliseconds.
#endif
#if USE_DS18020 == true
boolean ConvMLT_start = false;
#if USE_HLT == true
boolean ConvHLT_start = false;
#endif
#endif
#if USE_HLT == true
boolean HLT_is_On = false;
boolean HLT_block = false;
#endif
boolean pumpRest;
byte mainMenu = 0;
byte stageTime;
byte hopTime;
byte CurrentState = StageNothing;
byte WindowSize;
byte Direction;
byte Boil_output;
byte nmbrHops;
byte hopAdd;
byte MashState;
byte LogFactor = 0;
byte pumpTime;
double Input;
double Output;
double Setpoint;
#if FakeHeating == true
float Temp_MLT = 18.90;
float Plate_MLT = 18.90;
#else
float Temp_MLT = 0.0;
#endif
float boilStageTemp;
float stageTemp;
#if USE_HLT == true
#if FakeHeating == true
float Temp_HLT = 18.70;
float Plate_HLT = 18.70;
#else
float Temp_HLT = 0.0;
#endif
float HLT_SetPoint;
#endif
PID myPID(&Input, &Output, &Setpoint, 100, 40, 0, DIRECT);
void Temperature();
void PID_Heat(boolean);
void bk_heat_on();
void bk_heat_off();
void pump_off();
void HLT_on();
void HLT_off();
void Buzzer(byte, int);
#include "functions.h"
#include "timers.h"
#include "buttons.h"
#include "prompts.h"
#include "setup.h"
#if (DebugProcess == true || DebugPID == true)
void DebugTimeSerial() {
byte Hour, Minute, Second;
unsigned int Millisecond;
Hour = (byte) ((gCurrentTimeInMS / 1000) / 3600);
Minute = (byte)(((gCurrentTimeInMS / 1000) % 3600) / 60);
Second = (byte) ((gCurrentTimeInMS / 1000) % 60);
Millisecond = (unsigned int)gCurrentTimeInMS % 1000;
Serial.print("Time: ");
if (Hour < 10)
Serial.print("0");
Serial.print(Hour);
Serial.print(":");
if ( Minute < 10)
Serial.print("0");
Serial.print(Minute);
Serial.print(":");
if (Second < 10)
Serial.print("0");
Serial.print(Second);
Serial.print(".");
if (Millisecond < 10)
Serial.print("0");
if (Millisecond < 100)
Serial.print("0");
Serial.print(Millisecond);
Serial.print(" ");
}
#endif
#if USE_DS18020 == true
byte OwsInitialize(OneWire ows) {
if (ows.reset()) { // return 1 if present, 0 if not.
ows.skip();
return 1;
}
return 0;
}
void ReadOwSensor(OneWire ows, boolean & Convert_start, float & TempC, boolean Offset) {
byte data[9];
// start conversion and return
if (!(Convert_start)) {
if (! OwsInitialize(ows))
return;
ows.write(0x44, 0);
Convert_start = true;
return;
}
if (Convert_start) {
// check for conversion if it isn't complete return if it is then convert to decimal
if (ows.read_bit() == 0)
return;
// Allways a new start after the next steps
Convert_start = false;
if (OwsInitialize(ows)) {
ows.write(0xBE); // Read scratchpad
ows.read_bytes(data, 9);
if ( OneWire::crc8(data, 8) != data[8]) {
// if checksum fails start a new conversion.
#if DebugErrors == true
ew_byte(EM_ErrorNo(0), er_byte(EM_ErrorNo(0)) + 1); // error counter 0
#endif
return;
}
} else {
return;
}
/*
After a sensor is connected, or after power-up, the sensor resolution
can be different from what we desire. If so, configure the sensor and
start over again.
*/
if ((data[4] & 0x60) != 0x60) {
OwsInitialize(ows);
ows.write(0x4E); // Write scratchpad
ows.write(0); // TL register
ows.write(0); // TH register
ows.write(0x7F); // Configuration 12 bits, 750 ms
return;
}
int16_t raw = (data[1] << 8) | data[0];
/*
Check sign bits, must be all zero's or all one's.
*/
if ((raw & 0xf800) != 0) {
#if DebugErrors == true
ew_byte(EM_ErrorNo(1), er_byte(EM_ErrorNo(1)) + 1); // error counter 1
#endif
return;
}
if ((raw & 0xf800) == 0xf800) {
#if DebugErrors == true
ew_byte(EM_ErrorNo(2), er_byte(EM_ErrorNo(1)) + 2); // error counter 2
#endif
return;
}
if (Offset)
TempC = ((float)raw / 16.0) + ((float)((EEPROM.read(EM_TempOffset) - 50) / 10.0));
else
TempC = (float)raw / 16.0;
}
}
#endif // USE_DS18020
/*
Read Temperature sensors
*/
void Temperature() {
#if USE_DS18020 == true
ReadOwSensor(dsm, ConvMLT_start, Temp_MLT, true);
#if USE_HLT == true
ReadOwSensor(dsh, ConvHLT_start, Temp_HLT, false);
#endif
#endif // USE_DS18020
#if FakeHeating == true
TimerRun();
// Try to be as slow as a real sensor
if ((gCurrentTimeInMS - FakeHeatLastInMS) < 500)
return;
/*
Make this fake heater a bit more real by using a simulated heatplate.
We heatup that plate and then transfer the heat to the water.
That way we get a nice overshoot like in real life.
*/
if (digitalRead(HeatControlPin) == HIGH) {
if (Plate_MLT < 250.0)
Plate_MLT += (gCurrentTimeInMS - FakeHeatLastInMS) * 0.001; // Simulate plate upto 250 degrees
} else {
if (Plate_MLT > Temp_MLT)
Plate_MLT -= (gCurrentTimeInMS - FakeHeatLastInMS) * 0.00002 * (Plate_MLT - Temp_MLT);
}
// If plate is hotter then the water with a offset so that cooling later works.
if (Plate_MLT > (Temp_MLT + 5.0)) {
if (Temp_MLT < 100.05)
Temp_MLT += (gCurrentTimeInMS - FakeHeatLastInMS) * 0.000001 * (Plate_MLT - Temp_MLT);
}
// Allways loose heat to the air
if (Temp_MLT > 16.0) {
Temp_MLT -= (gCurrentTimeInMS - FakeHeatLastInMS) * 0.00000010 * (Temp_MLT - 16.0);
if (digitalRead(PumpControlPin) == HIGH) // More heat loss when pump is on
Temp_MLT -= (gCurrentTimeInMS - FakeHeatLastInMS) * 0.00000007 * (Temp_MLT - 16.0);
}
#if USE_HLT == true
if (digitalRead(HLTControlPin) == HIGH) {
if (Temp_HLT < 100.05)
Temp_HLT += (gCurrentTimeInMS - FakeHeatLastInMS) * 0.000055;
} else {
if (Temp_HLT > 16.0)
Temp_HLT -= (gCurrentTimeInMS - FakeHeatLastInMS) * 0.00000006 * (Temp_HLT - 16.0);
}
#endif
FakeHeatLastInMS = gCurrentTimeInMS;
#endif
}
#if USE_HLT == true
void HLT_Heat(void) {
(Temp_HLT < HLT_SetPoint) ? HLT_on() : HLT_off();
}
#endif
void LCDChar(byte X, byte Y, byte C) {
lcd.setCursor(X, Y);
lcd.write(C);
}
void LoadPIDsettings() {
// send the PID settings to the PID
myPID.SetTunings(er_byte(EM_PID_kP) - 100, (double)(er_byte(EM_PID_kI) / 1000.00), er_byte(EM_PID_kD) - 100);
WindowSize = er_byte(EM_WindowSize);
myPID.SetSampleTime(er_byte(EM_SampleTime) * 250);
LogFactor = er_byte(EM_LogFactor);
}
/*
PID control.
autoMode = true - PID is active.
autoMode = false - Output value is send as slow PWM
*/
void PID_Heat(boolean autoMode) {
double RealPower;
TimerRun();
#if DebugPID == true
static unsigned long LastTimeSpent;
if (TimeSpent != LastTimeSpent) {
DebugTimeSerial();
Serial.print(F("Mash Temp: "));
if (Temp_MLT < 10 && Temp_MLT >= 0) Serial.print(F(" "));
if (Temp_MLT < 100 && Temp_MLT >= 10) Serial.print(F(" "));
Serial.print(Temp_MLT);
Serial.print(F(" Setpoint: "));
if (Setpoint < 10 && Setpoint >= 0) Serial.print(F(" "));
if (Setpoint < 100 && Setpoint >= 10) Serial.print(F(" "));
Serial.print(Setpoint);
}
#endif
if (autoMode)
myPID.Compute();
/*
Apply logarithmic factor to the output.
*/
Output = int(Output);
RealPower = Output;
if (RealPower && LogFactor) {
/*
Make sure that even 1% Output results in enough power to actually heat the water.
*/
RealPower += ((255 - Output) / (21 - LogFactor));
}
if (gCurrentTimeInMS - w_StartTime > (unsigned int) WindowSize * 250) {
w_StartTime += (unsigned int)WindowSize * 250; //time to shift the Relay Window
}
((RealPower / 255) * ((unsigned int)WindowSize * 250) > gCurrentTimeInMS - w_StartTime) ? bk_heat_on() : bk_heat_off();
#if DebugPID == true
if (TimeSpent != LastTimeSpent) {
LastTimeSpent = TimeSpent;
Serial.print(F(" Output: "));
if (Output < 10 && Output >= 0) Serial.print(F(" "));
if (Output < 100 && Output >= 10) Serial.print(F(" "));
Serial.print(Output);
Serial.print(F(" RealPower="));
if (RealPower < 10 && RealPower >= 0) Serial.print(F(" "));
if (RealPower < 100 && RealPower >= 10) Serial.print(F(" "));
Serial.print(RealPower);
Serial.print(F(" LogFactor="));
Serial.print(LogFactor);
Serial.print(F(" Now: "));
Serial.print(gCurrentTimeInMS);
Serial.print(F(" w_StartTime: "));
Serial.println(w_StartTime);
}
#endif
}
/*
Boil/Mash kettle heat control
*/
void bk_heat_on() {
#if USE_HLT == true
HLT_block = true;
if (digitalRead(HLTControlPin) == HIGH) {
digitalWrite(HLTControlPin, LOW);
LCDChar(0, 1, 5);
}
#endif
digitalWrite(HeatControlPin, HIGH);
LCDChar(19, 1, 6);
}
void bk_heat_off() {
digitalWrite(HeatControlPin, LOW);
LCDChar(19, 1, 5);
#if USE_HLT == true
HLT_block = false;
if (HLT_is_On) {
digitalWrite(HLTControlPin, HIGH);
LCDChar(0, 1, 6);
}
#endif
}
void bk_heat_hide() {
digitalWrite(HeatControlPin, LOW);
LCDChar(19, 1, 32);
#if USE_HLT == true
HLT_block = false;
if (HLT_is_On) {
digitalWrite(HLTControlPin, HIGH);
LCDChar(0, 1, 6);
}
#endif
}
/*
Pump control.
*/
void pump_on() {
digitalWrite(PumpControlPin, HIGH);
LCDChar(19, 2, 4);
}
void pump_off() {
digitalWrite(PumpControlPin, LOW);
LCDChar(19, 2, 3);
}
void pump_hide() {
digitalWrite(PumpControlPin, LOW);
LCDChar(19, 2, 32);
}
/*
HLT heating control
*/
#if USE_HLT == true
void HLT_on() {
if (HLT_block == false) {
digitalWrite(HLTControlPin, HIGH);
LCDChar(0, 1, 6);
} else {
digitalWrite(HLTControlPin, LOW);
LCDChar(0, 1, 5);
}
HLT_is_On = true;
}
void HLT_off() {
digitalWrite(HLTControlPin, LOW);
LCDChar(0, 1, 5);
HLT_is_On = false;
}
void HLT_hide() {
digitalWrite(HLTControlPin, LOW);
LCDChar(0, 1, 32);
HLT_is_On = false;
}
#endif
/*
Center display values
*/
void DisplayValues(boolean PWM, boolean Timer, boolean HLTtemp, boolean HLTset) {
TimerRun();
Prompt(X1Y1_temp);
Prompt(X11Y1_setpoint);
#if USE_HLT == true
if (PWM && HLTtemp)
// Dual show Mash PWM and HLT temperature.
(TimeSpent % 5) ? Prompt(X1Y2_pwm) : Prompt(X1Y2_temp);
else if (PWM)
Prompt(X1Y2_pwm);
else if (HLTset)
Prompt(X1Y2_temp);
if (Timer && HLTset)
(TimeSpent % 5) ? Prompt(X11Y2_timer) : Prompt(X11Y2_setpoint);
else if (Timer)
Prompt(X11Y2_timer);
else if (HLTset)
Prompt(X11Y2_setpoint);
#else
if (PWM)
Prompt(X1Y2_pwm);
if (Timer)
Prompt(X11Y2_timer);
#endif
}
/*
Toggle pump
*/
void PumpControl() {
//turns the pump on or off
if (btn_Press(ButtonStartPin, 50))
(digitalRead(PumpControlPin) == HIGH) ? pump_hide() : pump_on();
}
/*
Iodine test, continue after user presses Enter
or after the iodine timeout.
*/
void IodineTest(void) {
byte IodineTime = er_byte(EM_IodoneTime);
TimerSet(IodineTime * 60);
while (true) {
Temperature();
Input = Temp_MLT;
Prompt(P0_iodine);
#if USE_HLT == true
DisplayValues(true, true, Temp_HLT != 0.0, true);
#else
DisplayValues(true, true, false, true);
#endif
PID_Heat(true);
#if USE_HLT == true
if (HLT_SetPoint)
HLT_Heat();
#endif
if (TimeSpent % 45 == 0)
Buzzer(1, 65);
Prompt(P3_xxxO);
if (btn_Press(ButtonEnterPin, 50) || (TimeLeft == 0)) {
return;
}
}
}
/*
Manual control
*/
void manual_mode() {
byte manualMenu = 0;
float mset_temp = 35.0;
boolean mheat = false;
boolean mtempReached = false;
boolean mreachedBeep = false;
#if USE_HLT == true
float hset_temp = 40.0;
boolean hheat = false;
boolean htempReached = false;
boolean hreachedBeep = false;
#endif
lcd.clear();
Prompt(P0_manual);
if (PromptForMashWater(true) == false) {
lcd.clear();
return;
}
#if USE_HLT == true
if (PromptForMashWater(false) == false) {
lcd.clear();
return;
}
#endif
Prompt(P1_clear);
LoadPIDsettings();
while (true) {
Temperature();
Setpoint = mset_temp;
Input = Temp_MLT;
if (mtempReached == false) {
if (Input >= Setpoint) {
mtempReached = true;
}
}
if (mtempReached && (mreachedBeep == false)) {
Buzzer(3, 250);
mreachedBeep = true;
}
(mheat) ? PID_Heat(true) : bk_heat_hide();
#if USE_HLT == true
HLT_SetPoint = hset_temp;
if (htempReached == false) {
if (Temp_HLT >= HLT_SetPoint) {
htempReached = true;
}
}
if (htempReached && (hreachedBeep == false)) {
Buzzer(3, 250);
hreachedBeep = true;
}
(hheat) ? HLT_Heat() : HLT_hide();
DisplayValues(mheat, false, true, true);
#else
DisplayValues(mheat, false, false, false);
#endif
switch (manualMenu) {
case 0: // manual Main menu
#if USE_HLT == true
Prompt(P3_HBPQ);
if (btn_Press(ButtonUpPin, 50))
manualMenu = 1;
#else
Prompt(P3_xBPQ);
#endif
if (btn_Press(ButtonDownPin, 50))
manualMenu = 2;
if (btn_Press(ButtonStartPin, 50))
manualMenu = 3;
if (btn_Press(ButtonEnterPin, 50)) {
lcd.clear();
bk_heat_hide();
pump_hide();
#if USE_HLT == true
HLT_hide();
#endif
return;
}
break;
#if USE_HLT == true
case 1: // manual Hot Liquer Tank
(hheat) ? Prompt(P3_UD0Q) : Prompt(P3_UD1Q);
ReadButton(Direction, Timer);
Set(hset_temp, 110, 20, 0.25, Timer, Direction);
if ((hset_temp - HLT_SetPoint) > 2) {
// Increased setting at least 2 degrees
htempReached = hreachedBeep = false;
}
if (btn_Press(ButtonStartPin, 50)) {
(hheat) ? hheat = false : hheat = true;
}
if (btn_Press(ButtonEnterPin, 50))
manualMenu = 0;
break;
#endif
case 2: // manual Boil Kettle heater
(mheat) ? Prompt(P3_UD0Q) : Prompt(P3_UD1Q);
ReadButton(Direction, Timer);
Set(mset_temp, 110, 20, 0.25, Timer, Direction);
if ((mset_temp - Setpoint) > 2) {
// Increased setting at least 2 degrees
mtempReached = mreachedBeep = false;
}
if (btn_Press(ButtonStartPin, 50)) {
(mheat) ? mheat = false : mheat = true;
}
if (btn_Press(ButtonEnterPin, 50))
manualMenu = 0;
break;
case 3: // manual Pump control.
(digitalRead(PumpControlPin) == HIGH) ? Prompt(P3_xx0Q) : Prompt(P3_xx1Q);
PumpControl();
if (btn_Press(ButtonEnterPin, 50))
manualMenu = 0;
break;
}
}
}
/*
Automatic brew control
*/
void auto_mode() {
byte NewState = StageInit;
byte tmpMinute = 0;
byte TimeWhirlPool;
byte _EM_StageTime;
byte _EM_PumpPreMash = er_byte(EM_PumpPreMash);
byte _EM_PumpOnMash = er_byte(EM_PumpOnMash);
byte _EM_PumpMashout = er_byte(EM_PumpMashout);
byte _EM_PumpOnBoil = er_byte(EM_PumpOnBoil);
byte _EM_PumpMaxTemp = er_byte(EM_PumpMaxTemp);
byte _EM_Whirlpool_9 = er_byte(EM_Whirlpool_9);
byte _EM_Whirlpool_7 = er_byte(EM_Whirlpool_7);
byte _EM_Whirlpool_6 = er_byte(EM_Whirlpool_6);
byte _EM_Whirlpool_2 = er_byte(EM_Whirlpool_2);
byte _EM_PumpCycle = er_byte(EM_PumpCycle);
byte _EM_PumpRest = er_byte(EM_PumpRest);
byte LastMashStep = 0;
byte ResumeTime;
boolean Resume = false;
boolean tempBoilReached = false;
boolean newMinute = false;
boolean Pwhirl;
boolean WP9Done = false;
boolean WP7Done = false;
boolean WP6Done = false;
boolean CoolBeep = false;
#if DebugProcess == true
boolean Debugger = false;
#endif
float _EM_StageTemp;
float DeltaTemp;
CurrentState = StageNothing;
LoadPIDsettings();
/*
See what our last Mash Step is
*/
for (byte i = 1; i < 7; i++) {
if (er_byte(EM_StageTime(i)))
LastMashStep = i;
}
#if DebugProcess == true
DebugTimeSerial();
Serial.print(F("Last Mash Step: "));
Serial.println(LastMashStep);
#endif
/*
Check for a crashed/unfinished brew
*/
if (er_byte(EM_AutoModeStarted)) {
lcd.clear();
if (WaitForConfirm(2, false, 0, P1_resume, 0, P3_proceed)) {
NewState = CurrentState = er_byte(EM_StageResume);
TimeLeft = ResumeTime = er_byte(EM_StageTimeLeft);
Resume = true;
MashState = MashNone;
pumpTime = 0;
pumpRest = false;
Temp_MLT = 65.2;
} else {
ew_byte(EM_AutoModeStarted, 0);
}
lcd.clear();
}
do {
startover:
Temperature();
Input = Temp_MLT;
TimerRun();
if ((byte)((TimeLeft % 3600) / 60) != tmpMinute) {
tmpMinute = (byte)((TimeLeft % 3600) / 60);
stageTime = (byte)(TimeLeft / 60);
ew_byte(EM_StageTimeLeft, stageTime);
newMinute = true;
}
/*
New state change
*/
if (NewState != CurrentState) {
#if DebugProcess == true
DebugTimeSerial();
Serial.print(F("Current State: "));
Serial.print(CurrentState);
Serial.print(F(" -> New State: "));
Serial.println(NewState);
#endif
lcd.clear();
bk_heat_hide();
pump_hide();
#if USE_HLT
HLT_hide();
#endif
/*
Do once the state we enter
*/
switch (NewState) {
case StageMashIn:
case StageMash1:
case StageMash2:
case StageMash3:
case StageMash4:
case StageMash5:
case StageMash6:
case StageMashOut:
MashState = MashNone;
pumpTime = 0;
pumpRest = false;
break;
case StageBoil:
Output = 255;
stageTemp = Setpoint = er_byte(EM_BoilTemperature);
stageTime = er_byte(EM_BoilTime);
Boil_output = er_byte(EM_BoilHeat);
hopAdd = 0;
ew_byte(EM_HopAddition, hopAdd);
nmbrHops = er_byte(EM_NumberOfHops);
hopTime = er_byte(EM_TimeOfHop(hopAdd));
break;
case StageCooling:
if (! WaitForConfirm(2, false, 0, P1_cool, 0, P3_proceed)) {
NewState = StageFinished;
goto startover;
}
lcd.clear();
CoolBeep = false;
if (_EM_Whirlpool_7 && ! WP7Done) {
stageTemp = 77.0;
} else if (_EM_Whirlpool_6 && ! WP6Done) {
stageTemp = 66.0;
} else {
stageTemp = word(er_byte(EM_CoolingTemp), er_byte(EM_CoolingTemp + 1)) / 16.0;
}
#if DebugProcess == true
DebugTimeSerial();
Serial.print(F("Start Cooling Temp="));
Serial.print(Temp_MLT);
Serial.print(F(" Target="));
Serial.println(stageTemp);
#endif
break;
case StageWhirlpool2:
case StageWhirlpool9:
case StageWhirlpool7:
case StageWhirlpool6:
if (! WaitForConfirm(2, false, 0, P1_whirl, 0, P3_proceed)) {
if (NewState == StageWhirlpool2)
NewState = StageFinished;
else
NewState = StageCooling;
goto startover;
}
lcd.clear();
Prompt(P1_twhirl);
if (_EM_Whirlpool_9 && ! WP9Done) {
TimeWhirlPool = _EM_Whirlpool_9;
Setpoint = 93.0;
} else if (_EM_Whirlpool_7 && ! WP7Done) {
TimeWhirlPool = _EM_Whirlpool_7;
Setpoint = 74.0;
} else if (_EM_Whirlpool_6 && ! WP6Done) {
TimeWhirlPool = _EM_Whirlpool_6;
Setpoint = 63.0;
} else {
TimeWhirlPool = _EM_Whirlpool_2;
}
Pwhirl = true;
while (Pwhirl) {
TimerShow(TimeWhirlPool * 60, 6, 2);
Prompt(P3_SGQO);