-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsourcecode.h
3382 lines (3110 loc) · 81.4 KB
/
sourcecode.h
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
// Please download all the library below and add it to your Arduino project.
// I apologise about this code. I was young ^^
//LIBRARIES
#include <ITDB02_Graph16.h>
#include <avr/pgmspace.h>
#include <ITDB02_Touch.h>
#include <Wire.h>
#include <EEPROM.h>
#include "writeAnything.h"
#include "readAnything.h"
#include <DS1307.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//Default Controller Settings
boolean RECOM_RCD = true; //For Mean Well drivers change "true" to "false"
boolean CLOCK_SCREENSAVER = true; //For a Clock Screensaver "true" / Blank Screen "false"
//You can turn the Screensaver ON/OFF in the pogram
//TOUCH PANEL and ITDB02 MEGA SHIELD
//(Mega Shield utilizes pins 5V, 3V3, GND, 2-6, 20-41, & (50-53 for SD Card))
ITDB02 myGLCD(38,39,40,41,ITDB32S); //May need to add "ITDB32S" depending on LCD controller
ITDB02_Touch myTouch(6,5,4,3,2);
//Declare which fonts to be utilized
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
//Images Alarme
extern unsigned int //image alarm
imagegreen[4096],
imagehot[4096],
imagecold[4096];
#define LARGE true
#define SMALL false
//Define the PWM PINS for the LEDs
const int ledPinWhite1 = 7;
const int ledPinWhite2 = 8;
const int ledPinRed = 9;
const int ledPinRoyalBlue = 10;
// Define the other DIGITAL and/or PWM PINS being used
const int relayPin1 = 42;
const int relayPin2 = 43;
const int relayPin3 = 44;
const int relayPin4 = 45;
const int alarmePin = 46; //Buzzer Alarm
const int engrais1Pin = 47;
const int engrais2Pin = 48;
float autoco2 = 1;
float manuelco2 = 0;
float autoalimled = 1;
float manuelalimled = 0;
float etat_alarme = 0 ;
float etat_relay1 = 0;
float etat_relay2 = 0;
float etat_relay3 = 0;
float etat_relay4 = 0;
// DS18B20 Temperature sensors plugged into pin 51 (Water, Hood, & Sump)
OneWire OneWireBus(51); //Choose a digital pin
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&OneWireBus);
// Assign the addresses of temperature sensors. Add/Change addresses as needed.
DeviceAddress waterThermometer = {
0x28, 0x5C, 0x56, 0x59, 0x03, 0x00, 0x00, 0xEB };
DeviceAddress pieceThermometer = {
0x28, 0xC8, 0x4E, 0x59, 0x03, 0x00, 0x00, 0xC4 };
float tempW = 0; //Water temperature values
float tempP = 0; //Ambiant temperature
int setTempScale = 0; //Celsius=0 || Fahrenheit=1 (change in prog)
float setTempC = 0.0; //Desired Water Temperature (User input in program)
float setTempF = 0.0;
float fanTempC = 0.0; //Desired Water Temp. Offsets for Heater & Chiller (User input in program)
float fanTempF = 0.0;
float alarmTempC = 0.0; //Temperature the Alarm will sound (User input in program)
float alarmTempF = 0.0;
long intervalAlarm = 1000 * 30; //Interval to beep the Alarm (1000 * seconds)
float temp2beS; //Temporary Temperature Values
float temp2beO; //Temporary Temperature Values
float temp2beA; //Temporary Temperature Values
String degC_F;
//RTC
int setCalendarFormat = 0; //DD/MM/YYYY=0 || Month DD, YYYY=1 (change in prog)
int setTimeFormat = 0; //24HR=0 || 12HR=1 (change in prog)
int rtc[7], rtcSet[7]; //Clock arrays
int rtcSet2, AM_PM, yTime; //Setting clock stuff
int timeDispH, timeDispM,
xTimeH, xTimeM10, xTimeM1,
xTimeAMPM, xColon;
byte data[56];
String time, date, day;
int dispScreen=0; //0-Main Screen, 1-Menu, 2-Clock Setup, 3-Temp Control,
//4-LED Test Options, 5-Test LED Arrays, 6-Test Individual
//LED Colors, 7-Choose LED Color, 8-View Selected Color
//Values, 9-Change Selected Color Array Values
//10-Wavemaker, 11-Wavemaker Settings, 12-General
//Settings, 13-Automatic Feeder, 14-Set Feeder Timers,
//15-About
int x, y; //touch coordinates
long previousMillisLED = 0; //Used in the Test LED Array Function
long previousMillisFive = 0; //Used in the Main Loop (Checks Time,Temp,LEDs,Screen)
long previousMillisAlarm = 0; //Used in the Alarm
int setScreensaver = 1; //ON=1 || OFF=2 (change in prog)
int screenSaverTimer = 0; //counter for Screen Saver
int setScreenSaverTimer = (15)*12; //how long in (minutes) before Screensaver comes
boolean SCREEN_RETURN = true; //Auto Return to mainScreen() after so long of inactivity
int returnTimer = 0; //counter for Screen Return
int setReturnTimer =
setScreenSaverTimer * .75; //Will return to main screen after 75% of the amount of
//time it takes before the screensaver turns on
int LedChangTime = 0; //LED change page, time and values
int min_cnt; //Used to determine the place in the color arrays
boolean LEDtestTick = false; //for testing LEDs and speed up clock
int white1Led, white2Led, royalblueLed, //previous LED output values
redLed;
int white1led_out, white2led_out, royalblueled_out, //current LED output values
redled_out, colorled_out;
int COLOR=0, WHITE1=1, WHITE2=2, //Used to Determine View/Change Color LED Values
ROYAL=4, RED=3;
boolean colorLEDtest = false; //To test individual color LEDs
int Rgad=0, Ggad=0, Bgad=0, //Used in the Test Ind. Color LEDs Gadget
Rfont=0, Gfont=0, Bfont=0,
Rback=0, Gback=0, Bback=0,
Rline=0, Gline=0, Bline=0;
int CL_1=0, CL_10=0, CL_100=0, //Used in the Test Ind. Color LEDs Gadget
cl_1, cl_10, cl_100;
int w2col_out, w1col_out, rbcol_out, //Current LED output values for Test Ind. Color LEDs
rcol_out;
int x1Bar=0, x2Bar=0, //Used in LED Output Chart on Test Ind. LEDs Screen
xValue=0, yValue=0,
LEDlevel, yBar;
//DIMMING VALUES can be changed below BUT the EEPROM must be cleared first.
//To CLEAR EEPROM, use arduino-0022\libraries\EEPROM\examples\eeprom_clear\eeprom_clear.pde
//and change the 512 to 4096 before Upload. After the LED comes on indicating the EEPROM
//has been cleared, it is now ok to change DIMMING VALUES below & Upload the sketch.
//SUMP Dimming Values 8pm to 8am
//REGULAR BLUE Dimming Values
//WHITE 1 Dimming Values (White LED array in RAM)
byte white1led[96] = {
0, 0, 0, 0, 0, 0, 0, 0, //0 - 1
0, 0, 0, 0, 0, 0, 0, 0, //2 - 3
0, 0, 0, 0, 0, 0, 0, 0, //4 - 5
0, 0, 0, 0, 0, 0, 0, 0, //6 - 7
0, 0, 0, 0, 0, 0, 0, 0, //8 - 9
28, 32, 38, 50, 70, 90, 90, 90, //10 - 11
95, 95, 95, 95, 105, 105, 105, 105, //12 - 13
120, 120, 120, 120, 125, 125, 125, 125, //14 - 15
125, 125, 125, 125, 120, 120, 120, 120, //16 - 17
115, 115, 115, 110, 100, 100, 95, 95, //18 - 19
70, 50, 38, 32, 28, 0, 0, 0, //20 - 21
0, 0, 0, 0, 0, 0, 0, 0 //22 - 23
};
//WHITE 2 Dimming Values (White LED array in RAM)
byte white2led[96] = {
0, 0, 0, 0, 0, 0, 0, 0, //0 - 1
0, 0, 0, 0, 0, 0, 0, 0, //2 - 3
0, 0, 0, 0, 0, 0, 0, 0, //4 - 5
0, 0, 0, 0, 0, 0, 0, 0, //6 - 7
0, 0, 0, 0, 0, 0, 0, 0, //8 - 9
28, 32, 38, 50, 70, 90, 90, 90, //10 - 11
95, 95, 95, 95, 105, 105, 105, 105, //12 - 13
120, 120, 120, 120, 125, 125, 125, 125, //14 - 15
125, 125, 125, 125, 120, 120, 120, 120, //16 - 17
115, 115, 115, 110, 100, 100, 95, 95, //18 - 19
70, 50, 38, 32, 28, 0, 0, 0, //20 - 21
0, 0, 0, 0, 0, 0, 0, 0 //22 - 23
};
//ROYAL BLUE Dimming Values
byte royalblueled[96] = {
0, 0, 0, 0, 0, 0, 0, 0, //0 - 1
0, 0, 0, 0, 0, 0, 0, 0, //2 - 3
0, 0, 0, 0, 0, 0, 0, 0, //4 - 5
0, 0, 0, 0, 0, 0, 35, 40, //6 - 7
40, 43, 47, 55, 65, 75, 80, 85, //8 - 9
90, 95, 95, 100, 110, 110, 115, 120, //10 - 11
125, 130, 135, 145, 145, 145, 150, 155, //12 - 13
160, 165, 170, 175, 180, 180, 180, 180, //14 - 15
180, 180, 180, 180, 175, 170, 165, 160, //16 - 17
155, 150, 145, 145, 145, 135, 130, 125, //18 - 19
120, 115, 110, 110, 100, 75, 65, 50, //20 - 21
40, 35, 33, 28, 0, 0, 0, 0 //22 - 23
};
//RED Dimming Values
byte redled[96] = {
0, 0, 0, 0, 0, 0, 0, 0, //0 - 1
0, 0, 0, 0, 0, 0, 0, 0, //2 - 3
0, 0, 0, 0, 0, 0, 0, 0, //4 - 5
0, 0, 0, 0, 0, 0, 0, 0, //6 - 7
0, 0, 0, 0, 0, 0, 0, 0, //8 - 9
0, 0, 0, 0, 0, 0, 0, 0, //10 - 11
30, 30, 40, 40, 50, 50, 60, 60, //12 - 13
60, 60, 50, 50, 40, 40, 30, 30, //14 - 15
0, 0, 0, 0, 0, 0, 0, 0, //16 - 17
0, 0, 0, 0, 0, 0, 0, 0, //18 - 19
0, 0, 0, 0, 0, 0, 0, 0, //20 - 21
0, 0, 0, 0, 0, 0, 0, 0
};
byte tled[96]; //Temporary Array to Hold changed LED Values
/**************************** CHOOSE OPTION MENU BUTTONS *****************************/
const int tanD[]= {
10, 29, 155, 59}; //"TIME and DATE" settings
const int gSet[]= {
10, 69, 155, 99}; //"GENERAL SETTINGS" page
const int tempSet[]= {
10, 109, 155, 139}; // Parametre temperature et ventilateur
const int co2Set[]= {
10, 149, 155, 179}; //"Parametre CO2 menu
const int engraisSet[]= {
165, 29, 310, 59}; //"Parametre Engrais menu
const int alimledSet[]= {
165, 69, 310, 99}; //"Parametre Alim LED menu
const int tesT[]= {
165, 109, 310, 139}; //"LED TESTING OPTIONS" menu
const int ledChM[]= {
165, 149, 310, 179}; //"CHANGE LED VALUES" menu
/**************************** TIME AND DATE SCREEN BUTTONS ***************************/
const int houU[]= {
110, 22, 135, 47}; //hour up
const int minU[]= {
180, 22, 205, 47}; //min up
const int ampmU[]= {
265, 22, 290, 47}; //AM/PM up
const int houD[]= {
110, 73, 135, 96}; //hour down
const int minD[]= {
180, 73, 205, 96}; //min down
const int ampmD[]= {
265, 73, 290, 96}; //AM/PM down
const int dayU[]= {
110, 112, 135, 137}; //day up
const int monU[]= {
180, 112, 205, 137}; //month up
const int yeaU[]= {
265, 112, 290, 137}; //year up
const int dayD[]= {
110, 162, 135, 187}; //day down
const int monD[]= {
180, 162, 205, 187}; //month down
const int yeaD[]= {
265, 162, 290, 187}; //year down
/*************************** H2O TEMP CONTROL SCREEN BUTTONS *************************/
const int temM[]= {
90, 49, 115, 74}; //temp. minus
const int temP[]= {
205, 49, 230, 74}; //temp. plus
const int offM[]= {
90, 99, 115, 124}; //offset minus
const int offP[]= {
205, 99, 230, 124}; //offset plus
const int almM[]= {
90, 149, 115, 174}; //alarm minus
const int almP[]= {
205, 149, 230, 174}; //alarm plus
/**************************** LED TESTING MENU BUTTONS *******************************/
const int tstLA[] = {
40, 59, 280, 99}; //"Test LED Array Output" settings
const int cntIL[] = {
40, 109, 280, 149}; //"Control Individual LEDs" settings
/********************** TEST LED ARRAY OUTPUT SCREEN BUTTONS *************************/
const int stsT[]= {
110, 105, 200, 175}; //start/stop
const int tenM[]= {
20, 120, 90, 160}; //-10s
const int tenP[]= {
220, 120, 290, 160}; //+10s
/******************** TEST INDIVIDUAL LED VALUES SCREEN BUTTONS **********************/
//These Buttons are made within the function
/****************** CHANGE INDIVIDUAL LED VALUES SCREEN BUTTONS **********************/
//These Buttons are made within the function
/************************* CHANGE LED VALUES MENU BUTTONS ****************************/
const int btCIL[]= {
5, 188, 90, 220}; //back to Change Individual LEDs Screen
const int ledChV[]= {
110, 200, 210, 220}; //LED Change Values
const int eeprom[]= {
215, 200, 315, 220}; //Save to EEPROM (Right Button)
/***************************** MISCELLANEOUS BUTTONS *********************************/
const int back[]= {
5, 200, 105, 220}; //BACK
const int prSAVE[]= {
110, 200, 210, 220}; //SAVE
const int canC[]= {
215, 200, 315, 220}; //CANCEL
/**************************** END OF PRIMARY BUTTONS *********************************/
/********************************* EEPROM FUNCTIONS ***********************************/
struct config_g
{
int calendarFormat;
int timeFormat;
int tempScale;
int SCREENsaver;
}
GENERALsettings;
struct config_t
{
int tempset;
int tempFset;
int tempoff;
int tempFoff;
int tempalarm;
int tempFalarm;
}
tempSettings;
struct config_c
{
int autoco2set;
int manuelco2set;
}
co2Settings;
struct config_a
{
int autoalimledset;
int manuelalimledset;
}
alimledSettings;
void SaveLEDToEEPROM()
{
EEPROM.write(0, 123); //to determine if data available in EEPROM
for (int i=1; i<97; i++)
{
EEPROM.write(i+(96*0), white1led[i]);
EEPROM.write(i+(96*1), white2led[i]);
EEPROM.write(i+(96*2), royalblueled[i]);
EEPROM.write(i+(96*3), redled[i]);
}
}
void SaveGenSetsToEEPROM()
{
GENERALsettings.calendarFormat = int(setCalendarFormat);
GENERALsettings.timeFormat = int(setTimeFormat);
GENERALsettings.tempScale = int(setTempScale);
GENERALsettings.SCREENsaver = int(setScreensaver);
EEPROM_writeAnything(660, GENERALsettings);
}
void Saveco2SetsToEEPROM()
{
co2Settings.autoco2set = int(autoco2);
co2Settings.manuelco2set = int(manuelco2);
EEPROM_writeAnything(620, co2Settings);
}
void SavealimledSetsToEEPROM()
{
alimledSettings.autoalimledset = int(autoalimled);
alimledSettings.manuelalimledset = int(manuelalimled);
EEPROM_writeAnything(600, alimledSettings);
}
void SaveTempToEEPROM()
{
tempSettings.tempset = int(setTempC*10);
tempSettings.tempFset = int(setTempF*10);
tempSettings.tempoff = int(fanTempC*10);
tempSettings.tempFoff = int(fanTempF*10);
tempSettings.tempalarm = int(alarmTempC*10);
tempSettings.tempFalarm = int(alarmTempF*10);
EEPROM_writeAnything(640, tempSettings);
}
void ReadFromEEPROM()
{
int k = EEPROM.read(0);
char tempString[3];
if (k==123) {
for (int i=1; i<97; i++) {
white1led[i] = EEPROM.read(i+(96*0));
white2led[i] = EEPROM.read(i+(96*1));
royalblueled[i] = EEPROM.read(i+(96*2));
redled[i] = EEPROM.read(i+(96*3));
}
}
EEPROM_readAnything(640, tempSettings);
setTempC = tempSettings.tempset;
setTempC /=10;
setTempF = tempSettings.tempFset;
setTempF /=10;
fanTempC = tempSettings.tempoff;
fanTempC /=10;
fanTempF = tempSettings.tempFoff;
fanTempF /=10;
alarmTempC = tempSettings.tempalarm;
alarmTempC /= 10;
alarmTempF = tempSettings.tempFalarm;
alarmTempF /= 10;
EEPROM_readAnything(660, GENERALsettings);
setCalendarFormat = GENERALsettings.calendarFormat;
setTimeFormat = GENERALsettings.timeFormat;
setTempScale = GENERALsettings.tempScale;
setScreensaver = GENERALsettings.SCREENsaver;
EEPROM_readAnything(620, co2Settings);
autoco2 = co2Settings.autoco2set;
manuelco2 = co2Settings.manuelco2set;
EEPROM_readAnything(600, alimledSettings);
autoalimled = alimledSettings.autoalimledset;
manuelalimled = alimledSettings.manuelalimledset;
}
/***************************** END OF EEPROM FUNCTIONS ********************************/
/********************************** RTC FUNCTIONS *************************************/
void SaveRTC()
{
int year=rtcSet[6] - 2000;
RTC.stop(); //RTC clock setup
RTC.set(DS1307_SEC,1);
RTC.set(DS1307_MIN,rtcSet[1]);
RTC.set(DS1307_HR,rtcSet[2]);
//RTC.set(DS1307_DOW,1);
RTC.set(DS1307_DATE,rtcSet[4]);
RTC.set(DS1307_MTH,rtcSet[5]);
RTC.set(DS1307_YR,year);
delay(10);
RTC.start();
delay(10);
for(int i=0; i<56; i++)
{
RTC.set_sram_byte(65,i);
}
delay(50);
}
/********************************* END OF RTC FUNCTIONS *******************************/
/********************************** TIME AND DATE BAR **********************************/
void TimeDateBar(boolean refreshAll=false)
{
String oldVal, rtc1, rtc2, ampm, month;
if ((rtc[1]>=0) && (rtc[1]<=9))
{
rtc1= '0' + String(rtc[1]);
} //adds 0 to minutes
else {
rtc1= String(rtc[1]);
}
if (setTimeFormat==1)
{
if (rtc[2]==0) {
rtc2= 12;
} //12 HR Format
else {
if (rtc[2]>12) {
rtc2= rtc[2]-12;
}
else {
rtc2= String(rtc[2]);
}
}
}
if(rtc[2] < 12){
ampm= " AM ";
} //Adding the AM/PM sufffix
else {
ampm= " PM ";
}
oldVal = time; //refresh time if different
if (setTimeFormat==1)
{
time= rtc2 + ':' + rtc1 + ampm;
}
else {
time= " " + String(rtc[2]) + ':' + rtc1 +" ";
}
if ((oldVal!=time) || refreshAll)
{
char bufferT[9];
time.toCharArray(bufferT, 9); //String to Char array
setFont(SMALL, 255, 255, 0, 64, 64, 64);
myGLCD.print(bufferT, 215, 227); //Display time
}
if (rtc[5]==1) {
month= "JAN ";
} //Convert the month to its name
if (rtc[5]==2) {
month= "FEB ";
}
if (rtc[5]==3) {
month= "MAR ";
}
if (rtc[5]==4) {
month= "APR ";
}
if (rtc[5]==5) {
month= "MAY ";
}
if (rtc[5]==6) {
month= "JUN ";
}
if (rtc[5]==7) {
month= "JLY ";
}
if (rtc[5]==8) {
month= "AUG ";
}
if (rtc[5]==9) {
month= "SEP ";
}
if (rtc[5]==10) {
month= "OCT ";
}
if (rtc[5]==11) {
month= "NOV ";
}
if (rtc[5]==12) {
month= "DEC ";
}
oldVal = date; //refresh date if different
if (setCalendarFormat==0)
{
date= " " + String(rtc[4]) + '/' + String(rtc[5]) + '/' + String(rtc[6]) + " ";
}
else
{
date= " " + month + String(rtc[4]) + ',' + ' ' + String(rtc[6]);
}
if ((oldVal!=date) || refreshAll)
{
char bufferD[15];
date.toCharArray(bufferD, 15); //String to Char array
setFont(SMALL, 255, 255, 0, 64, 64, 64);
myGLCD.print(bufferD, 20, 227); //Display date
}
}
/****************************** END OF TIME AND DATE BAR ******************************/
/******************************** TEMPERATURE FUNCTIONS *******************************/
void checkTempC()
{
sensors.requestTemperatures(); // call sensors.requestTemperatures() to issue a global
// temperature request to all devices on the bus
tempW = (sensors.getTempC(waterThermometer)); //read water temperature
tempP = (sensors.getTempC(pieceThermometer)); //read hood's heatsink temperature
if (tempW<(setTempC+alarmTempC) && tempW>(setTempC-alarmTempC)) {
etat_alarme = 0;
digitalWrite(alarmePin, LOW); //turn off alarm
}
if (tempW<(setTempC+fanTempC)) //turn off ventilateur
{
etat_relay4 = 0;
digitalWrite(relayPin4, LOW);
}
if (fanTempC>0)
{
if (tempW >=(setTempC+fanTempC)) //turn on ventilateur turn off chauffage
{
etat_relay4 = 1;
etat_relay2 = 0;
digitalWrite(relayPin2, LOW);
digitalWrite(relayPin4, HIGH);
}
if (tempW < (setTempC+fanTempC)) //turn on chauffage
{
etat_relay2 = 1;
digitalWrite(relayPin2, HIGH);
}
if (tempW <= (setTempC-fanTempC))
{
etat_relay2 = 1;
digitalWrite(relayPin2, HIGH);
}
}
if (alarmTempC>0) //turn on alarm
{
if ((tempW>=(setTempC+alarmTempC)) || (tempW<=(setTempC-alarmTempC)))
{
etat_alarme = 1;
unsigned long cMillis = millis();
if (cMillis - previousMillisAlarm > intervalAlarm)
{
previousMillisAlarm = cMillis;
digitalWrite(alarmePin, HIGH);
delay(1000);
digitalWrite(alarmePin, LOW);
}
}
}
}
/*************************** END OF TEMPERATURE FUNCTIONS *****************************/
/************************************* COMMANDE RELAY *************************************/
void CommandeRelay()
{
if (autoco2 == 1)
{
if ((white1led_out > 0) && (white2led_out > 0)) // commande relay 1 = co2Set
{
etat_relay1 = 1;
digitalWrite(relayPin1, HIGH);
}
else
{
etat_relay1 = 0;
digitalWrite(relayPin1, LOW);
}
}
if (autoco2 == 0)
{
if (manuelco2 == 1)
{
etat_relay1 = 1;
digitalWrite(relayPin1, HIGH);
}
else
{
etat_relay1 = 0;
digitalWrite(relayPin1, LOW);
}
}
if (autoalimled == 1)
{
if ((white1led_out == 0) && (white2led_out == 0) && (redled_out == 0) && (royalblueled_out == 0)) // commande relay 3 = Alimentation LED
{
etat_relay3 = 0;
digitalWrite(relayPin3, LOW);
}
else
{
etat_relay3 = 1;
digitalWrite(relayPin3, HIGH);
}
}
if (autoalimled == 0)
{
if (manuelalimled == 1)
{
etat_relay3 = 1;
digitalWrite(relayPin3, HIGH);
}
else
{
etat_relay3 = 0;
digitalWrite(relayPin3, LOW);
}
}
}
/************************************* LED LEVELS *************************************/
void LED_levels_output()
{
int sector, sstep, t1, t2 ;
int w1_out, w2_out, rb_out, r_out;
if (min_cnt>=1440) {
min_cnt=1;
} // 24 hours of minutes
sector = min_cnt/15; // divided by gives sector -- 15 minute
sstep = min_cnt%15; // remainder gives add on to sector value
t1 =sector;
if (t1==95) {
t2=0;
}
else {
t2 = t1+1;
}
if (colorLEDtest)
{
white1led_out = w1col_out;
white2led_out = w2col_out;
royalblueled_out = rbcol_out;
redled_out = rcol_out;
}
else
{
if (sstep==0)
{
white1led_out = white1led[t1];
white2led_out = white2led[t1];
royalblueled_out = royalblueled[t1];
redled_out = redled[t1];
}
else
{
white1led_out = check(&white1led[t1], &white1led[t2], sstep);
white2led_out = check(&white2led[t1], &white2led[t2], sstep);
royalblueled_out = check(&royalblueled[t1], &royalblueled[t2], sstep);
redled_out = check(&redled[t1], &redled[t2], sstep);
}
}
if (RECOM_RCD) {
w1_out = white1led_out;
w2_out = white2led_out;
rb_out = royalblueled_out;
r_out = redled_out;
}
else {
w1_out = 255 - white1led_out;
w2_out = 255 - white2led_out;
rb_out = 255 - royalblueled_out;
r_out = 255 - redled_out;
}
analogWrite(ledPinWhite1, w1_out);
analogWrite(ledPinWhite2, w2_out);
analogWrite(ledPinRoyalBlue, rb_out);
analogWrite(ledPinRed, r_out);
}
int check( byte *pt1, byte *pt2, int lstep)
{
int result;
float fresult;
if (*pt1==*pt2) {
result = *pt1;
} // No change
else if (*pt1<*pt2) //Increasing brightness
{
fresult = ((float(*pt2-*pt1)/15.0) * float(lstep))+float(*pt1);
result = int(fresult);
}
//Decreasing brightness
else {
fresult = -((float(*pt1-*pt2)/15.0) * float(lstep))+float(*pt1);
result = int(fresult);
}
return result;
}
/********************************* END OF LED LEVELS **********************************/
/********************************* MISC. FUNCTIONS ************************************/
void clearScreen()
{
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(1, 15, 318, 226);
}
void printButton(char* text, int x1, int y1, int x2, int y2, boolean fontsize = false)
{
int stl = strlen(text);
int fx, fy;
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (x1, y1, x2, y2);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
myGLCD.setBackColor(0, 0, 255);
if (fontsize) {
myGLCD.setFont(BigFont);
fx = x1+(((x2 - x1+1)-(stl*16))/2);
fy = y1+(((y2 - y1+1)-16)/2);
myGLCD.print(text, fx, fy);
}
else {
myGLCD.setFont(SmallFont);
fx = x1+(((x2 - x1)-(stl*8))/2);
fy = y1+(((y2 - y1-1)-8)/2);
myGLCD.print(text, fx, fy);
}
}
void printCenter(char* text, int x1, int y1, int x2, int y2)
{
int stl = strlen(text);
int fx, fy;
fx = x1+(((x2 - x1)-(stl*8))/2);
fy = y1+(((y2 - y1-1)-8)/2);
myGLCD.print(text, fx, fy);
}
void printLedChangerP(char* text, int x1, int y1, int x2, int y2, boolean fontsize = false)
{
int stl = strlen(text);
int fx, fy;
myGLCD.setColor(255, 255, 255);
myGLCD.fillRect (x1, y1, x2, y2);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRect (x1, y1, x2, y2);
myGLCD.setBackColor(255, 255, 255);
myGLCD.setColor(255, 0, 0);
if (fontsize) {
myGLCD.setFont(BigFont);
fx = x1+(((x2 - x1+1)-(stl*16))/2);
fy = y1+(((y2 - y1+1)-16)/2);
myGLCD.print(text, fx, fy);
}
else {
myGLCD.setFont(SmallFont);
fx = x1+(((x2 - x1)-(stl*8))/2);
fy = y1+(((y2 - y1-1)-8)/2);
myGLCD.print(text, fx, fy);
}
}
void printLedChangerM(char* text, int x1, int y1, int x2, int y2, boolean fontsize = false)
{
int stl = strlen(text);
int fx, fy;
myGLCD.setColor(255, 255, 255);
myGLCD.fillRect (x1, y1, x2, y2);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRect (x1, y1, x2, y2);
myGLCD.setBackColor(255, 255, 255);
myGLCD.setColor(0, 0, 255);
if (fontsize) {
myGLCD.setFont(BigFont);
fx = x1+(((x2 - x1+1)-(stl*16))/2);
fy = y1+(((y2 - y1+1)-16)/2);
myGLCD.print(text, fx, fy);
}
else {
myGLCD.setFont(SmallFont);
fx = x1+(((x2 - x1)-(stl*8))/2);
fy = y1+(((y2 - y1-1)-8)/2);
myGLCD.print(text, fx, fy);
}
}
void printHeader(char* headline)
{
setFont(SMALL, 255, 255, 0, 255, 255, 0);
myGLCD.fillRect (1, 1, 318, 14);
myGLCD.setColor(0, 0, 0);
myGLCD.print(headline, CENTER, 1);
}
void setFont(boolean font, byte cr, byte cg, byte cb, byte br, byte bg, byte bb)
{
myGLCD.setBackColor(br, bg, bb); //font background black
myGLCD.setColor(cr, cg, cb); //font color white
if (font==LARGE)
myGLCD.setFont(BigFont); //font size LARGE
else if (font==SMALL)
myGLCD.setFont(SmallFont);
}
void waitForIt(int x1, int y1, int x2, int y2) // Draw a red frame while a button is touched
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
while (myTouch.dataAvailable()) {
myTouch.read();
}
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
void waitForItSq(int x1, int y1, int x2, int y2) // Draw a red frame while a button is touched
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRect (x1, y1, x2, y2);
while (myTouch.dataAvailable()) {
myTouch.read();
}
myGLCD.setColor(255, 255, 255);
myGLCD.drawRect (x1, y1, x2, y2);
}
int LedToPercent (int Led_out) //returns LED output in %
{
int result;
if (Led_out==0) {
result = 0;
}
else {
result = map(Led_out, 1, 255, 1, 100);
}
return result;
}
void drawBarGraph()
{
myGLCD.setColor(255, 255, 255); //LED Chart
setFont(SMALL, 255, 255, 255, 0, 0, 0);
myGLCD.drawRect(30, 137, 113, 138); //x-line
myGLCD.drawRect(30, 137, 31, 36); //y-line
for (int i=0; i<5; i++) //tick-marks
{
myGLCD.drawLine(31, (i*20)+36, 35, (i*20)+36);
}
myGLCD.print("100", 4, 30);
myGLCD.print("80", 12, 50);
myGLCD.print("60", 12, 70);
myGLCD.print("40", 12, 90);
myGLCD.print("20", 12, 110);
myGLCD.print("0", 20, 130);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRect(40, 136, 52, 135); //white1 %bar place holder
myGLCD.setColor(255, 255, 255);
myGLCD.drawRect(57, 136, 69, 135); //white2 %bar place holder
myGLCD.setColor(255, 0, 0);
myGLCD.drawRect(74, 136, 86, 135); //red %bar place holder
myGLCD.setColor(58, 95, 205);
myGLCD.drawRect(91, 136, 103, 135); //royal %bar place holder
}
void drawBarandColorValue()
{
colorled_out = CL_100 + CL_10 + CL_1;
setFont(SMALL, Rback, Gback, Bback, Rback, Gback, Bback);
myGLCD.print(" ", xValue, yValue); //fill over old
setFont(SMALL, Rfont, Gfont, Bfont, Rback, Gback, Bback);
myGLCD.printNumI(colorled_out, xValue, yValue);
yBar = 136 - colorled_out*.39;
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(x1Bar, yBar, x2Bar, 36); //hide end of last bar
myGLCD.setColor(Rgad, Ggad, Bgad);
myGLCD.fillRect(x1Bar, 136, x2Bar, yBar); //color percentage bar
if (COLOR==RED) {
rcol_out=colorled_out;
}
if (COLOR==WHITE1) {
w1col_out=colorled_out;
}
if (COLOR==WHITE2) {
w2col_out=colorled_out;
}
if (COLOR==ROYAL) {
rbcol_out=colorled_out;
}
}
void ledChangerGadget()
{
myGLCD.setColor(Rgad, Ggad, Bgad);
myGLCD.fillRoundRect(199, 25, 285, 132); //Gadget Color
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(204, 50, 280, 74); //Black Background of Numbers
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect(199, 25, 285, 132); //Outline Gadget
myGLCD.setColor(Rline, Gline, Bline); //Line Color
myGLCD.drawLine(199, 46, 285, 46);
setFont(SMALL, Rfont, Gfont, Bfont, Rback, Gback, Bback);
if (COLOR==0){
myGLCD.print("COLOR", 202, 28);
}
if (COLOR==1){
myGLCD.print("BLANC 1", 202, 28);