-
Notifications
You must be signed in to change notification settings - Fork 0
/
LCD.ino
1845 lines (1695 loc) · 56.6 KB
/
LCD.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
//Timer
static uint32_t current_millis = 0;
//LovyanGFX Library
#define LGFX_USE_V1
#include <LovyanGFX.hpp>
#include <lgfx/v1/platforms/esp32s3/Panel_RGB.hpp>
#include <lgfx/v1/platforms/esp32s3/Bus_RGB.hpp>
#include <driver/i2c.h>
//LovyanGFX Class
class LGFX : public lgfx::LGFX_Device {
public:
lgfx::Bus_RGB _bus_instance;
lgfx::Panel_RGB _panel_instance;
lgfx::Light_PWM _light_instance;
lgfx::Touch_GT911 _touch_instance;
LGFX(void) {
{
auto cfg = _panel_instance.config();
cfg.memory_width = 800;
cfg.memory_height = 480;
cfg.panel_width = 800;
cfg.panel_height = 480;
cfg.offset_x = 0;
cfg.offset_y = 0;
_panel_instance.config(cfg);
}
{
auto cfg = _bus_instance.config();
cfg.panel = &_panel_instance;
cfg.pin_d0 = GPIO_NUM_15; // B0
cfg.pin_d1 = GPIO_NUM_7; // B1
cfg.pin_d2 = GPIO_NUM_6; // B2
cfg.pin_d3 = GPIO_NUM_5; // B3
cfg.pin_d4 = GPIO_NUM_4; // B4
cfg.pin_d5 = GPIO_NUM_9; // G0
cfg.pin_d6 = GPIO_NUM_46; // G1
cfg.pin_d7 = GPIO_NUM_3; // G2
cfg.pin_d8 = GPIO_NUM_8; // G3
cfg.pin_d9 = GPIO_NUM_16; // G4
cfg.pin_d10 = GPIO_NUM_1; // G5
cfg.pin_d11 = GPIO_NUM_14; // R0
cfg.pin_d12 = GPIO_NUM_21; // R1
cfg.pin_d13 = GPIO_NUM_47; // R2
cfg.pin_d14 = GPIO_NUM_48; // R3
cfg.pin_d15 = GPIO_NUM_45; // R4
cfg.pin_henable = GPIO_NUM_41;
cfg.pin_vsync = GPIO_NUM_40;
cfg.pin_hsync = GPIO_NUM_39;
cfg.pin_pclk = GPIO_NUM_0;
cfg.freq_write = 8000000; //12000000
cfg.hsync_polarity = 0;
cfg.hsync_front_porch = 40;
cfg.hsync_pulse_width = 48;
cfg.hsync_back_porch = 40;
cfg.vsync_polarity = 0;
cfg.vsync_front_porch = 1;
cfg.vsync_pulse_width = 31;
cfg.vsync_back_porch = 13;
cfg.pclk_active_neg = 1;
cfg.de_idle_high = 0;
cfg.pclk_idle_high = 0;
_bus_instance.config(cfg);
}
_panel_instance.setBus(&_bus_instance);
{
auto cfg = _light_instance.config();
cfg.pin_bl = GPIO_NUM_2;
_light_instance.config(cfg);
}
_panel_instance.light(&_light_instance);
{
auto cfg = _touch_instance.config();
cfg.x_min = 0;
cfg.x_max = 799;
cfg.y_min = 0;
cfg.y_max = 479;
cfg.pin_int = -1;
cfg.pin_rst = -1;
cfg.bus_shared = false;
cfg.offset_rotation = 0;
cfg.i2c_port = I2C_NUM_1;
cfg.pin_sda = GPIO_NUM_19;
cfg.pin_scl = GPIO_NUM_20;
cfg.freq = 400000;
cfg.i2c_addr = 0x14;
_touch_instance.config(cfg);
_panel_instance.setTouch(&_touch_instance);
}
setPanel(&_panel_instance);
}
};
//LovyanGFX
LGFX lcd;
//GT911 XY
int32_t touch_x;
int32_t touch_y;
int32_t last_x = 0;
int32_t last_y = 0;
bool pump_button = false;
bool gutter_button = false;
bool makeup_button = false;
bool nozzle_ink_button = false;
bool nozzle_cleaning_button = false;
bool nozzle_vacuum_button = false;
bool flush_viscosimeter_button = false;
bool circulation_pumps_button = false;
int temperature_regulation_button = 0;
bool viscosimeter_button = false;
//I2C
#include "Wire.h"
#define SDA 10
#define SCL 11
//MCP23017
#define MCP23017_ADRESS 0x27 //MCP Adress
#define IODIRA 0x00 //Register for INPUT/OUTPUT A
#define IODIRB 0x01 //Register for INPUT/OUTPUT B
#define GPIOA 0x12 //Register for HIGH/LOW A
#define GPIOB 0x13 //Register for HIGH/LOW B
#define GPPUA 0x0C //Register for Pullup A
#define GPPUB 0x0D //Register for Pullup B
#define PINMODE_A 0x01 //A 00000001 0 = Output 1 = Input
#define PINMODE_B 0x01 //B 00000001 0 = Output 1 = Input
#define PULLUP_A 0x01 //A 00000001 0 = Output 1 = Input
#define PULLUP_B 0x01 //B 00000001 0 = Output 1 = Input
//MCP23017 Input Pinout
#define VISCOSIMETER_UPPER_SWITCH 'B', 0
#define VISCOSIMETER_LOWER_SWITCH 'A', 0
//MCP23017 Output Pinout
#define GUTTER_PIN mcp_out_bit_12
#define MAKEUP_PIN mcp_out_bit_14
#define NOZZLE_INK_PIN mcp_out_bit_13
#define NOZZLE_CLEANING_PIN mcp_out_bit_7
#define NOZZLE_VACUUM_PIN mcp_out_bit_4
#define FLUSH_VISCOSIMETER_PIN mcp_out_bit_15
#define CIRCULATION_TANKS_PIN mcp_out_bit_6
#define VISCOSIMETER_PIN mcp_out_bit_5
#define PRESSURE_PUMP_0_PIN mcp_out_bit_3
#define PRESSURE_PUMP_1_PIN mcp_out_bit_11
#define PRESSURE_PUMP_2_PIN mcp_out_bit_2
#define PRESSURE_PUMP_3_PIN mcp_out_bit_10
#define DIR_PIN_B mcp_out_bit_16
#define DIR_PIN_A mcp_out_bit_8
#define NO_OUTPUT_15 mcp_out_bit_1 //Used as Input
#define NO_OUTPUT_16 mcp_out_bit_9 //Used as Input
//MCP23017 Output Bits
int mcp_out_value_1; //A0
int mcp_out_value_2; //A1
int mcp_out_value_3; //A2
int mcp_out_value_4; //A3
int mcp_out_value_5; //A4
int mcp_out_value_6; //A5
int mcp_out_value_7; //A6
int mcp_out_value_8; //A7
int mcp_out_value_9; //B0
int mcp_out_value_10; //B1
int mcp_out_value_11; //B2
int mcp_out_value_12; //B3
int mcp_out_value_13; //B4
int mcp_out_value_14; //B5
int mcp_out_value_15; //B6
int mcp_out_value_16; //B7
bool mcp_out_bit_1 = false;
bool mcp_out_bit_2 = false;
bool mcp_out_bit_3 = false;
bool mcp_out_bit_4 = false;
bool mcp_out_bit_5 = false;
bool mcp_out_bit_6 = false;
bool mcp_out_bit_7 = false;
bool mcp_out_bit_8 = false;
bool mcp_out_bit_9 = false;
bool mcp_out_bit_10 = false;
bool mcp_out_bit_11 = false;
bool mcp_out_bit_12 = false;
bool mcp_out_bit_13 = false;
bool mcp_out_bit_14 = false;
bool mcp_out_bit_15 = false;
bool mcp_out_bit_16 = false;
int io_a_value = 0;
int previous_io_a_value = 0;
int io_b_value = 0;
int previous_io_b_value = 0;
byte io_input_a = 0;
byte io_input_b = 0;
//DS3231
#define DS3231_ADDRESS 0x68
int years, months, days, day_of_week, hours, minutes, seconds;
char time_buffer[30];
char date_buffer[30];
String ds3231_temp;
String fraction;
String current_day_of_week;
uint8_t fractions;
const byte number_of_chars = 129;
char received_chars[number_of_chars];
bool new_serial_data = false;
static char dts_string[19];
int16_t ds3231_int_temp;
//ADS1115
#define ADS1115 0x48
#define CONFIG_REGISTER 1
#define CONFIG_BYTE_1 0b10000011
#define CONVERSION_REGISTER 0
#define ADS_BUFFERCOUNT 16
const uint8_t CONFIG_BYTE_0[4] = { 0b11010000, 0b11100000, 0b11110000, 0b11000000 };
const float VOLTS_PER_STEP = 6.144 / 32768.0;
uint16_t ADS_buffers[4][ADS_BUFFERCOUNT];
static String pressure;
static String viscosimeter_temperature;
static String nozzle_temperature;
static String conductivity;
//Viscosimeter
unsigned long viscosimeter_pause = 10000;
unsigned long viscosimeter_timeout = 90000;
unsigned int viscosimeter_pump_time = 3000;
unsigned long viscosimeter_counter_millis = 0;
unsigned long viscosimeter_pause_millis = 0;
unsigned long viscosimeter_pump_millis = 0;
unsigned int viscosimeter_case = 0;
//Warnings
unsigned long waste_tank_full_millis = 0;
bool waste_tank_warning_led = false;
//PID Temperature Control
#include <PID_v1.h>
#define PELTIER_PWM_PIN 12
double Setpoint, Input, Output;
double Kp = 75.0, Ki = 1.0, Kd = 0.5;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, REVERSE);
//Wifi
#include <WiFi.h>
#define WIFI_SSID ""
#define WIFI_PASSWORD ""
//Datalogger
//#include <WiFiClient.h>
//#include <FTPClient_Generic.h>
// char ftp_server[] = "192.168.188.1";
// char ftp_user[] = "ftpuser";
// char ftp_pass[] = "L6KW70";
// char dirName[] = "/";
// FTPClient_Generic ftp(ftp_server, ftp_user, ftp_pass, 60000);
//DB
typedef struct db_entry {
uint32_t date_time;
int16_t room_temperature;
uint16_t nozzle_temperature;
uint16_t viscosimeter_temperature;
uint32_t fall_time;
uint16_t pressure;
uint16_t tds;
uint16_t feature_bit;
} db_entry;
db_entry ftp_current;
uint64_t last_ftp_current = 0;
uint32_t timestamp = 0;
//Google Sheets
#include <ESP_Google_Sheet_Client.h>
#define PROJECT_ID ""
#define CLIENT_EMAIL ""
#define USER_EMAIL ""
const char PRIVATE_KEY[] PROGMEM = "";
bool taskComplete = false;
//Setup
void setup() {
//Serial
Serial.begin(115200);
Serial.println("START");
//LCD
lcd.init();
lcd.setBrightness(255);
lcd.fillScreen(TFT_BLACK);
lcd.setFont(&fonts::AsciiFont8x16);
lcd.setTextColor(TFT_WHITE, TFT_BLACK);
lcd.fillRect(5, 5, 30, 30, TFT_RED); // Pump
lcd.fillRect(5, 45, 30, 30, TFT_RED); // Gutter
lcd.fillRect(5, 85, 30, 30, TFT_RED); // MakeUp
lcd.fillRect(5, 125, 30, 30, TFT_RED); // Nozzle Ink
lcd.fillRect(5, 165, 30, 30, TFT_RED); // Nozzle Cleaning
lcd.fillRect(5, 205, 30, 30, TFT_RED); // Nozzle Vacuum
lcd.fillRect(5, 245, 30, 30, TFT_RED); // Nozzle MakeUp
lcd.fillRect(5, 285, 30, 30, TFT_RED); // Vent Waste Tank
lcd.fillRect(5, 325, 30, 30, TFT_RED); // Temperature Regulation
lcd.fillRect(5, 365, 30, 30, TFT_RED); // Viscosimeter
lcd.fillRect(5, 405, 30, 30, TFT_RED); // Waste Tank Full
lcd.fillRect(5, 445, 30, 30, TFT_RED); // CIJ Printer
lcd.drawString("Pressure Pumps", 50, 15);
lcd.drawString("Gutter Valve", 50, 55);
lcd.drawString("MakeUp Pump", 50, 95);
lcd.drawString("Nozzle Ink Valve", 50, 135);
lcd.drawString("Nozzle Vacuum Valve", 50, 175);
lcd.drawString("Viscosimeter", 50, 215);
lcd.drawString("Flush Line", 50, 255);
lcd.drawString("Circulation Pumps", 50, 295);
lcd.drawString("Temperature Regulation", 50, 335);
lcd.drawString("Return Pump", 50, 375);
lcd.drawString("Not Used", 50, 415);
lcd.drawString("WiFi", 50, 455);
lcd.drawString(" Sunday", 720, 455);
lcd.drawString("Viscosity: 0000 ms", 615, 5);
//MCP IO
Wire.begin(SDA, SCL);
Wire.beginTransmission(MCP23017_ADRESS);
Wire.write(IODIRA);
Wire.write(PINMODE_A);
Wire.endTransmission();
Wire.beginTransmission(MCP23017_ADRESS);
Wire.write(IODIRB);
Wire.write(PINMODE_B);
Wire.endTransmission();
Wire.beginTransmission(MCP23017_ADRESS);
Wire.write(GPPUA);
Wire.write(PULLUP_A);
Wire.endTransmission();
Wire.beginTransmission(MCP23017_ADRESS);
Wire.write(GPPUB);
Wire.write(PULLUP_B);
Wire.endTransmission();
//ADS1115
InitAverages();
//PID Temperature Control
//ledcSetup(0, 1000, 8);
//ledcAttachPin(PELTIER_PWM_PIN, 0);
ledcAttach(PELTIER_PWM_PIN, 1000, 8);
Input = 25;
Setpoint = 25;
//myPID.SetMode(AUTOMATIC);
//Wifi
WiFi.disconnect(true);
WiFi.onEvent(WiFiStationConnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_CONNECTED);
WiFi.onEvent(WiFiGotIP, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);
WiFi.onEvent(WiFiStationDisconnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.println();
Serial.println();
Serial.println("Wait for WiFi... ");
//Google Sheets
GSheet.setPrerefreshSeconds(10 * 60);
GSheet.begin(CLIENT_EMAIL, PROJECT_ID, PRIVATE_KEY);
}
//Valve Functions
//ON
void pump_on() {
if (pump_button == false) {
Serial.println("Pump ON");
lcd.fillRect(5, 5, 30, 30, TFT_GREEN);
pump_button = true;
bitset(0b0000000000000001);
}
}
void gutter_on() {
if (gutter_button == false) {
Serial.println("Gutter ON");
lcd.fillRect(5, 45, 30, 30, TFT_GREEN);
gutter_button = true;
GUTTER_PIN = true;
bitset(0b0000000000000010);
}
}
void makeup_on() {
if (makeup_button == false) {
Serial.println("MakeUp ON");
lcd.fillRect(5, 85, 30, 30, TFT_GREEN);
makeup_button = true;
MAKEUP_PIN = true;
bitset(0b0000000000000100);
}
}
void nozzle_ink_on() {
if (nozzle_ink_button == false) {
Serial.println("Nozzle Ink ON");
lcd.fillRect(5, 125, 30, 30, TFT_GREEN);
nozzle_ink_button = true;
NOZZLE_INK_PIN = true;
bitset(0b0000000000001000);
}
}
void nozzle_vacuum_on() {
if (nozzle_vacuum_button == false) {
Serial.println("Nozzle Vacuum ON");
lcd.fillRect(5, 165, 30, 30, TFT_GREEN);
nozzle_vacuum_button = true;
NOZZLE_VACUUM_PIN = true;
bitset(0b0000000000010000);
}
}
void viscosimeter_on() {
if (viscosimeter_button == false) {
Serial.println("Viscosimeter ON");
lcd.fillRect(5, 205, 30, 30, TFT_GREEN);
viscosimeter_button = true;
bitset(0b0000000000100000);
}
}
void flush_viscosimeter_on() {
if (flush_viscosimeter_button == false) {
Serial.println("Flush Viscosimeter ON");
lcd.fillRect(5, 245, 30, 30, TFT_GREEN);
flush_viscosimeter_button = true;
FLUSH_VISCOSIMETER_PIN = true;
bitset(0b0000000001000000);
}
}
void circulation_pumps_on() {
if (circulation_pumps_button == false) {
Serial.println("Circulation Pumps ON");
lcd.fillRect(5, 285, 30, 30, TFT_GREEN);
circulation_pumps_button = true;
CIRCULATION_TANKS_PIN = true;
bitset(0b0000000010000000);
}
}
void temperature_regulation_heat() {
if (temperature_regulation_button == 0) {
lcd.fillRect(5, 325, 30, 30, TFT_ORANGE);
Serial.println("Temperature Regulation Heating");
temperature_regulation_button = 1;
bitset(0b0000000100000000);
}
}
void temperature_regulation_cool() {
if (temperature_regulation_button == 2) {
lcd.fillRect(5, 325, 30, 30, TFT_BLUE);
Serial.println("Temperature Regulation Cooling");
temperature_regulation_button = 3;
bitset(0b0000001000000000);
}
}
void return_pump_on() {
if (nozzle_cleaning_button == false) {
Serial.println("Not Used ON");
lcd.fillRect(5, 365, 30, 30, TFT_GREEN);
nozzle_cleaning_button = true;
NOZZLE_CLEANING_PIN = true;
bitset(0b0000100000000000);
}
}
void viscosimeter_pump_on() {
VISCOSIMETER_PIN = true;
}
//OFF
void pump_off() {
if (pump_button == true) {
Serial.println("Pump OFF");
lcd.fillRect(5, 5, 30, 30, TFT_RED);
pump_button = false;
bitclear(0b0000000000000001);
}
}
void gutter_off() {
if (gutter_button == true) {
Serial.println("Gutter OFF");
lcd.fillRect(5, 45, 30, 30, TFT_RED);
gutter_button = false;
GUTTER_PIN = false;
bitclear(0b0000000000000010);
}
}
void makeup_off() {
if (makeup_button == true) {
Serial.println("MakeUp OFF");
lcd.fillRect(5, 85, 30, 30, TFT_RED);
makeup_button = false;
MAKEUP_PIN = false;
bitclear(0b0000000000000100);
}
}
void nozzle_ink_off() {
if (nozzle_ink_button == true) {
Serial.println("Nozzle Ink OFF");
lcd.fillRect(5, 125, 30, 30, TFT_RED);
nozzle_ink_button = false;
NOZZLE_INK_PIN = false;
bitclear(0b0000000000001000);
}
}
void nozzle_vacuum_off() {
if (nozzle_vacuum_button == true) {
Serial.println("Nozzle Vacuum OFF");
lcd.fillRect(5, 165, 30, 30, TFT_RED);
nozzle_vacuum_button = false;
NOZZLE_VACUUM_PIN = false;
bitclear(0b0000000000010000);
}
}
void viscosimeter_off() {
if (viscosimeter_button == true) {
Serial.println("Viscosimeter OFF");
lcd.fillRect(5, 205, 30, 30, TFT_RED);
viscosimeter_button = false;
bitclear(0b0000000000100000);
}
}
void flush_viscosimeter_off() {
if (flush_viscosimeter_button == true) {
Serial.println("Flush Viscosimeter OFF");
lcd.fillRect(5, 245, 30, 30, TFT_RED);
flush_viscosimeter_button = false;
FLUSH_VISCOSIMETER_PIN = false;
bitclear(0b0000000001000000);
}
}
void circulation_pumps_off() {
if (circulation_pumps_button == true) {
Serial.println("Circulation Pumps OFF");
lcd.fillRect(5, 285, 30, 30, TFT_RED);
circulation_pumps_button = false;
CIRCULATION_TANKS_PIN = false;
bitclear(0b0000000010000000);
}
}
void temperature_regulation_heat_off() {
if (temperature_regulation_button == 1) {
Serial.println("Temperature Regulation OFF");
lcd.fillRect(5, 325, 30, 30, TFT_RED);
temperature_regulation_button = 2;
bitclear(0b0000001100000000);
}
}
void temperature_regulation_cool_off() {
if (temperature_regulation_button == 3) {
Serial.println("Temperature Regulation OFF");
lcd.fillRect(5, 325, 30, 30, TFT_RED);
temperature_regulation_button = 0;
bitclear(0b0000001100000000);
}
}
void return_pump_off() {
if (nozzle_cleaning_button == true) {
Serial.println("Not Used OFF");
lcd.fillRect(5, 365, 30, 30, TFT_RED);
nozzle_cleaning_button = false;
NOZZLE_CLEANING_PIN = false;
bitclear(0b0000100000000000);
}
}
void viscosimeter_pump_off() {
VISCOSIMETER_PIN = false;
}
//GT911 Buttons
void touch_buttons() {
//Pump Button
if (pump_button == false) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 5 && touch_y <= 35) {
last_x = touch_x;
last_y = touch_y;
pump_on();
}
}
}
}
if (pump_button == true) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 5 && touch_y <= 35) {
last_x = touch_x;
last_y = touch_y;
pump_off();
}
}
}
}
//Gutter Button
if (gutter_button == false) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 45 && touch_y <= 75) {
last_x = touch_x;
last_y = touch_y;
gutter_on();
}
}
}
}
if (gutter_button == true) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 45 && touch_y <= 75) {
last_x = touch_x;
last_y = touch_y;
gutter_off();
}
}
}
}
// MakeUp Button
if (makeup_button == false) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 85 && touch_y <= 115) {
last_x = touch_x;
last_y = touch_y;
makeup_on();
}
}
}
}
if (makeup_button == true) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 85 && touch_y <= 115) {
last_x = touch_x;
last_y = touch_y;
makeup_off();
}
}
}
}
// Nozzle Ink Button
if (nozzle_ink_button == false) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 125 && touch_y <= 155) {
last_x = touch_x;
last_y = touch_y;
nozzle_ink_on();
}
}
}
}
if (nozzle_ink_button == true) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 125 && touch_y <= 155) {
last_x = touch_x;
last_y = touch_y;
nozzle_ink_off();
}
}
}
}
// Viscosimeter Button
if (viscosimeter_button == false) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 205 && touch_y <= 235) {
last_x = touch_x;
last_y = touch_y;
viscosimeter_on();
}
}
}
}
if (viscosimeter_button == true) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 205 && touch_y <= 235) {
last_x = touch_x;
last_y = touch_y;
viscosimeter_off();
}
}
}
}
// Nozzle Vacuum Button
if (nozzle_vacuum_button == false) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 165 && touch_y <= 195) {
last_x = touch_x;
last_y = touch_y;
nozzle_vacuum_on();
}
}
}
}
if (nozzle_vacuum_button == true) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 165 && touch_y <= 195) {
last_x = touch_x;
last_y = touch_y;
nozzle_vacuum_off();
}
}
}
}
// Nozzle MakeUp Button
if (flush_viscosimeter_button == false) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 245 && touch_y <= 275) {
last_x = touch_x;
last_y = touch_y;
flush_viscosimeter_on();
}
}
}
}
if (flush_viscosimeter_button == true) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 245 && touch_y <= 275) {
last_x = touch_x;
last_y = touch_y;
flush_viscosimeter_off();
}
}
}
}
// Vent Waste Tank Button
if (circulation_pumps_button == false) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 285 && touch_y <= 315) {
last_x = touch_x;
last_y = touch_y;
circulation_pumps_on();
}
}
}
}
if (circulation_pumps_button == true) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 285 && touch_y <= 315) {
last_x = touch_x;
last_y = touch_y;
circulation_pumps_off();
}
}
}
}
// Temperature Regulation
if (temperature_regulation_button == 0) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 325 && touch_y <= 355) {
last_x = touch_x;
last_y = touch_y;
temperature_regulation_heat();
}
}
}
}
if (temperature_regulation_button == 1) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 325 && touch_y <= 355) {
last_x = touch_x;
last_y = touch_y;
temperature_regulation_heat_off();
}
}
}
}
if (temperature_regulation_button == 2) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 325 && touch_y <= 355) {
last_x = touch_x;
last_y = touch_y;
temperature_regulation_cool();
}
}
}
}
if (temperature_regulation_button == 3) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 325 && touch_y <= 355) {
last_x = touch_x;
last_y = touch_y;
temperature_regulation_cool_off();
}
}
}
}
// Nozzle Cleaning Button
if (nozzle_cleaning_button == false) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 365 && touch_y <= 395) {
last_x = touch_x;
last_y = touch_y;
return_pump_on();
}
}
}
}
if (nozzle_cleaning_button == true) {
if (touch_x != last_x || touch_y != last_y) {
if (touch_x >= 5 && touch_x <= 35) {
if (touch_y >= 365 && touch_y <= 395) {
last_x = touch_x;
last_y = touch_y;
return_pump_off();
}
}
}
}
}
//GT911 Touchscreen
void touchscreen() {
if (lcd.getTouch(&touch_x, &touch_y)) {
}
}
//MCP23017 Write
void mcp23017_write() {
if (mcp_out_bit_1 == true) {
mcp_out_value_1 = 0;
} else {
mcp_out_value_1 = 1;
}
if (mcp_out_bit_2 == true) {
mcp_out_value_2 = 0;
} else {
mcp_out_value_2 = 2;
}
if (mcp_out_bit_3 == true) {
mcp_out_value_3 = 0;
} else {
mcp_out_value_3 = 4;
}
if (mcp_out_bit_4 == true) {
mcp_out_value_4 = 0;
} else {
mcp_out_value_4 = 8;
}
if (mcp_out_bit_5 == true) {
mcp_out_value_5 = 0;
} else {
mcp_out_value_5 = 16;
}
if (mcp_out_bit_6 == true) {
mcp_out_value_6 = 0;
} else {
mcp_out_value_6 = 32;
}
if (mcp_out_bit_7 == true) {
mcp_out_value_7 = 0;
} else {
mcp_out_value_7 = 64;
}
if (mcp_out_bit_8 == true) {
mcp_out_value_8 = 128;
} else {
mcp_out_value_8 = 0;
}
if (mcp_out_bit_9 == true) {
mcp_out_value_9 = 0;
} else {
mcp_out_value_9 = 1;
}
if (mcp_out_bit_10 == true) {
mcp_out_value_10 = 0;
} else {
mcp_out_value_10 = 2;
}
if (mcp_out_bit_11 == true) {
mcp_out_value_11 = 0;
} else {
mcp_out_value_11 = 4;
}
if (mcp_out_bit_12 == true) {
mcp_out_value_12 = 0;
} else {
mcp_out_value_12 = 8;
}
if (mcp_out_bit_13 == true) {
mcp_out_value_13 = 0;
} else {
mcp_out_value_13 = 16;
}
if (mcp_out_bit_14 == true) {
mcp_out_value_14 = 0;
} else {
mcp_out_value_14 = 32;
}
if (mcp_out_bit_15 == true) {
mcp_out_value_15 = 0;
} else {
mcp_out_value_15 = 64;
}
if (mcp_out_bit_16 == true) {
mcp_out_value_16 = 128;
} else {
mcp_out_value_16 = 0;
}
io_a_value = (mcp_out_value_1 + mcp_out_value_2 + mcp_out_value_3 + mcp_out_value_4 + mcp_out_value_5 + mcp_out_value_6 + mcp_out_value_7 + mcp_out_value_8);
if (previous_io_a_value != io_a_value) {
Wire.beginTransmission(MCP23017_ADRESS);
Wire.write(GPIOA);
Wire.write(io_a_value);
Wire.endTransmission();
Serial.println(io_a_value, BIN);
previous_io_a_value = io_a_value;
}
io_b_value = (mcp_out_value_9 + mcp_out_value_10 + mcp_out_value_11 + mcp_out_value_12 + mcp_out_value_13 + mcp_out_value_14 + mcp_out_value_15 + mcp_out_value_16);
if (previous_io_b_value != io_b_value) {
Wire.beginTransmission(MCP23017_ADRESS);
Wire.write(GPIOB);
Wire.write(io_b_value);
Wire.endTransmission();
Serial.println(io_b_value, BIN);
previous_io_b_value = io_b_value;
}
}
//MCP23017 Read
bool mcp23017_read(char gpio, int bit) {
int gpio_register = 0;
Wire.beginTransmission(MCP23017_ADRESS);
Wire.write(GPIOA);
Wire.endTransmission();
Wire.requestFrom(MCP23017_ADRESS, 1);
io_input_a = Wire.read();
Wire.beginTransmission(MCP23017_ADRESS);
Wire.write(GPIOB);
Wire.endTransmission();
Wire.requestFrom(MCP23017_ADRESS, 1);
io_input_b = Wire.read();
if (gpio == 'A') {
gpio_register = io_input_a;
}
if (gpio == 'B') {
gpio_register = io_input_b;
}
if (bitRead(gpio_register, bit) == 0) {