-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReceiver_v1.cpp
More file actions
2142 lines (1929 loc) · 67.6 KB
/
Receiver_v1.cpp
File metadata and controls
2142 lines (1929 loc) · 67.6 KB
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
#include <Adafruit_SH1106.h> // Library for OLED display
#include <SPI.h> // SPI library for Arduino Ethernet
#include <Arduino.h>
#include <nRF24L01.h> // Library for nRF24L01 module
#include <RF24.h> // RF24 library for nRF24L01 module
#include <Wire.h> // I2C library
#include <Adafruit_GFX.h> // Graphics library for OLED
#include <ezButton.h> // Button library for debouncing
#define OLED_RESET 4 // OLED reset pin
Adafruit_SH1106 display(OLED_RESET);
#define SCREEN_WIDTH 128 // OLED screen width
#define SCREEN_HEIGHT 64 // OLED screen height
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
// Button and state variables
const int buttonPin = 22;
int buttonState = 0; // Current button state
int lastButtonState = 0; // Previous button state
int variableValue = 0; // Variable for current value (1 to 3)
int previousValue = 0; // Store previous value
// LED pin definitions
const int ledPins[] = { 40, 38, 36, 34, 32, 26, 28, 24 };
// RJ45, RJ11 and BNC pin definitions
const int portPins[] = { 23, 25, 27, 29, 33, 37, 39, 41 };
const int numPins = sizeof(portPins) / sizeof(portPins[0]);
const int rj11Pins[] = { 44, 46 };
const int num2Pins = sizeof(rj11Pins) / sizeof(rj11Pins[0]);
const int bncPins[] = { 47, 45 };
const int num3Pins = sizeof(bncPins) / sizeof(bncPins[0]);
// Various string configurations for ports, options, and wiring
String receivedMessage = "";
String binaryValue = "00001000";
String binaryValue2 = "00001000";
String binaryString3 = "00010000";
String binaryString4 = "10000000";
String options[] = { "TEST CONTINUITY", "TEST SHORT", "TEST WIRING", "MANUAL" };
int numOpt = sizeof(options) / sizeof(options[0]);
String ports[] = { "RJ45 T568A", "RJ45 T568B", "BNC", "RJ11" };
int numPorts = sizeof(ports) / sizeof(ports[0]);
String wireColour1[] = { "White/Green", "Green", "White/Orange", "Blue", "White/Blue", "Orange", "White/Brown", "Brown" };
int num568a = sizeof(wireColour1) / sizeof(wireColour1[0]);
String wireColour2[] = { "White/Orange", "Orange", "White/Green", "Blue", "White/Blue", "Green", "White/Brown", "Brown" };
int num568b = sizeof(wireColour2) / sizeof(wireColour2[0]);
String wireColour3[] = { "BLACK/GND", "RED/SIGNAL" };
// Rotary encoder pins
#define CLK_PIN 10
#define DT_PIN 4
#define SW_PIN 8
// Encoder and button variables
int counter = 0;
int CLK_state;
int prev_CLK_state;
volatile unsigned int encoderPos = 0;
int currentValue = encoderPos;
boolean buttonPressed = false;
ezButton button(SW_PIN); // Using the ezButton library for debouncing
// nRF24L01 radio setup
const byte address[6] = "00001";
RF24 radio(2, 11); // CE, CSN pins
// Function declarations
void function1();
void function2();
void function3();
void function4();
void (*functions[])() = { function1, function2, function3, function4 };
void setup() {
Serial.begin(9600);
// Button pin configuration
pinMode(buttonPin, INPUT_PULLUP);
// Configure LED pins as outputs
for (int i = 0; i < 8; i++) {
pinMode(ledPins[i], OUTPUT);
}
// Configure rotary encoder pins
pinMode(CLK_PIN, INPUT);
pinMode(DT_PIN, INPUT);
button.setDebounceTime(50);
prev_CLK_state = digitalRead(CLK_PIN);
// Initialize RF module
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_LOW);
radio.startListening();
// Initialize OLED display
display.begin(SH1106_SWITCHCAPVCC, 0x3C);
display.display();
delay(2000);
display.clearDisplay();
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
// Configure RJ45 pins
for (int i = 0; i < numPins; ++i) {
pinMode(portPins[i], OUTPUT);
}
for (int i = 0; i < num2Pins; ++i) {
pinMode(rj11Pins[i], OUTPUT);
pinMode(bncPins[i], OUTPUT);
}
}
void loop() {
// Reset LED states
for (int i = 0; i < 8; i++) {
digitalWrite(ledPins[i], LOW);
}
button.loop();
CLK_state = digitalRead(CLK_PIN);
// Handle rotary encoder movement
if (CLK_state != prev_CLK_state && CLK_state == HIGH) {
if (digitalRead(DT_PIN) == HIGH) {
encoderPos = (encoderPos - 1 + 4) % 4;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
} else {
encoderPos = (encoderPos + 1) % 4;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
}
}
prev_CLK_state = CLK_state;
// Check button press
if (button.isPressed()) {
buttonPressed = true;
}
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
variableValue++;
delay(500);
if (variableValue > 3) {
variableValue = 0;
}
Serial.println(variableValue);
}
// Call selected function when encoder button is pressed
int index = encoderPos;
if (buttonPressed) {
buttonPressed = false;
functions[encoderPos]();
}
// Update OLED display
display.clearDisplay();
display.setCursor(0, 0);
display.print("MODE: ");
display.println(options[index]);
display.setCursor(0, 20);
display.print("PORT: ");
display.println(ports[variableValue]);
display.display();
}
void function1() {
Serial.println("TEST CONTINUITY SELECTED");
String binaryValue = "00000001";
String binaryValue2 = "00001000";
String binaryString3 = "00010000";
String receivedMessage = ""; // String object to store received message
char text[32] = "";
int d = 0;
int p;
while (encoderPos == 0) {
String binaryString3 = "00010000";
int k = 0;
int t = 5;
if (variableValue == 0) {
for (int i = 0; i < numPins; i++) {
button.loop();
CLK_state = digitalRead(CLK_PIN);
if (CLK_state != prev_CLK_state && CLK_state == HIGH) {
if (digitalRead(DT_PIN) == HIGH) {
encoderPos = (encoderPos + 1) % 3;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
break;
} else {
encoderPos = (encoderPos - 1 + 3) % 3;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
break;
}
}
prev_CLK_state = CLK_state;
char lastBit = binaryValue2[binaryValue2.length() - 1]; // Store the last bit
binaryValue2 = lastBit + binaryValue2.substring(0, binaryValue2.length() - 1); // Shift all bits to the right
Serial.print("BIN: ");
Serial.println(binaryValue2); // Print the binary representation
char lastBit2 = binaryValue[binaryValue.length() - 1]; // Store the last bit
binaryValue = lastBit2 + binaryValue.substring(0, binaryValue.length() - 1); // Shift all bits to the right
// Serial.print("BIN: ");
// Serial.println(binaryValue); // Print the binary representation
digitalWrite(portPins[i], HIGH);
for (int w = 0; w <= 7; w++) {
digitalWrite(ledPins[w], binaryValue.charAt(w) == '1' ? HIGH : LOW);
}
delay(300); // Adjust delay as needed
if (radio.available()) {
radio.read(&text, sizeof(text));
receivedMessage = text; // Copy char array to String object
Serial.print("RX: ");
Serial.println(receivedMessage);
delay(500);
if (binaryValue2[t] == receivedMessage[t]) {
if (binaryValue2 == "10000000") {
p = 8;
} else if (binaryValue2 == "01000000") {
p = 7;
}
if (binaryValue2 == "00100000") {
p = 6;
} else if (binaryValue2 == "00010000") {
p = 5;
}
if (binaryValue2 == "00001000") {
p = 4;
} else if (binaryValue2 == "00000100") {
p = 3;
}
if (binaryValue2 == "00000010") {
p = 2;
} else if (binaryValue2 == "00000001") {
p = 1;
}
k++;
// Binary representation of matched pin
Serial.print("Pin ");
Serial.print(p);
Serial.println(" matched!");
display.clearDisplay();
display.setCursor(0, 16);
display.print("SENT: ");
display.println(binaryValue2);
display.print("RECV: ");
display.println(receivedMessage);
display.setCursor(0, 40);
display.print("Pin:");
display.print(p);
display.print(" CONNECTED");
display.setCursor(0, 48);
display.print("WIRCLR: ");
display.print(wireColour1[p - 1]);
display.display();
} else {
if (binaryValue2 == "10000000") {
p = 8;
} else if (binaryValue2 == "01000000") {
p = 7;
}
if (binaryValue2 == "00100000") {
p = 6;
} else if (binaryValue2 == "00010000") {
p = 5;
}
if (binaryValue2 == "00001000") {
p = 4;
} else if (binaryValue2 == "00000100") {
p = 3;
}
if (binaryValue2 == "00000010") {
p = 2;
} else if (binaryValue2 == "00000001") {
p = 1;
}
display.clearDisplay();
display.setCursor(0, 0);
display.println("TEST CONTINUITY FAIL");
display.setCursor(0, 16);
display.print("SENT: ");
display.println(binaryValue2);
display.print("RECV: ");
display.println(receivedMessage);
display.setCursor(0, 40);
display.print("Pin:");
display.print(p);
display.print("NOT CONNECTED");
display.setCursor(0, 48);
display.print("WIRCLR: ");
display.print(wireColour1[p - 1]);
display.display();
}
} else {
display.clearDisplay();
display.setCursor(0, 16);
display.println("NO DATA RECIEVED");
display.display();
}
t++;
if (t > 7) {
t = 0;
}
if (k == 8) {
display.setCursor(0, 0);
display.println("TEST CONTINUITY PASS");
// Display buffer
display.display();
}
digitalWrite(portPins[i], LOW);
}
}
if (variableValue == 1) {
for (int i = 0; i < numPins; i++) {
button.loop();
CLK_state = digitalRead(CLK_PIN);
if (CLK_state != prev_CLK_state && CLK_state == HIGH) {
if (digitalRead(DT_PIN) == HIGH) {
encoderPos = (encoderPos + 1) % 3;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
break;
} else {
encoderPos = (encoderPos - 1 + 3) % 3;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
break;
}
}
prev_CLK_state = CLK_state;
// Set the current pin high and others low
int p;
char lastBit = binaryValue2[binaryValue2.length() - 1]; // Store the last bit
binaryValue2 = lastBit + binaryValue2.substring(0, binaryValue2.length() - 1); // Shift all bits to the right
Serial.print("BIN: ");
Serial.println(binaryValue2); // Print the binary representation
char lastBit2 = binaryValue[binaryValue.length() - 1]; // Store the last bit
binaryValue = lastBit2 + binaryValue.substring(0, binaryValue.length() - 1); // Shift all bits to the right
// Serial.print("BIN: ");
// Serial.println(binaryValue); // Print the binary representation
digitalWrite(portPins[i], HIGH);
for (int w = 0; w <= 7; w++) {
digitalWrite(ledPins[w], binaryValue.charAt(w) == '1' ? HIGH : LOW);
}
delay(300); // Adjust delay as needed
if (radio.available()) {
radio.read(&text, sizeof(text));
receivedMessage = text; // Copy char array to String object
Serial.print("RX: ");
Serial.println(receivedMessage);
delay(500);
if (binaryValue2[t] == receivedMessage[t]) {
if (binaryValue2 == "10000000") {
p = 8;
} else if (binaryValue2 == "01000000") {
p = 7;
}
if (binaryValue2 == "00100000") {
p = 6;
} else if (binaryValue2 == "00010000") {
p = 5;
}
if (binaryValue2 == "00001000") {
p = 4;
} else if (binaryValue2 == "00000100") {
p = 3;
}
if (binaryValue2 == "00000010") {
p = 2;
} else if (binaryValue2 == "00000001") {
p = 1;
}
k++;
// Binary representation of matched pin
Serial.print("Pin ");
Serial.print(p);
Serial.println(" matched!");
display.clearDisplay();
display.setCursor(0, 16);
display.print("SENT: ");
display.println(binaryValue2);
display.print("RECV: ");
display.println(receivedMessage);
display.setCursor(0, 40);
display.print("Pin:");
display.print(p);
display.print(" CONNECTED");
display.setCursor(0, 48);
display.print("WIRCLR: ");
display.print(wireColour2[p - 1]);
display.display();
} else {
if (binaryValue2 == "10000000") {
p = 8;
} else if (binaryValue2 == "01000000") {
p = 7;
}
if (binaryValue2 == "00100000") {
p = 6;
} else if (binaryValue2 == "00010000") {
p = 5;
}
if (binaryValue2 == "00001000") {
p = 4;
} else if (binaryValue2 == "00000100") {
p = 3;
}
if (binaryValue2 == "00000010") {
p = 2;
} else if (binaryValue2 == "00000001") {
p = 1;
}
display.clearDisplay();
display.setCursor(0, 0);
display.println("TEST CONTINUITY FAIL");
display.setCursor(0, 16);
display.print("SENT: ");
display.println(binaryValue2);
display.print("RECV: ");
display.println(receivedMessage);
display.setCursor(0, 40);
display.print("Pin:");
display.print(p);
display.print("NOT CONNECTED");
display.setCursor(0, 48);
display.print("WIRCLR: ");
display.print(wireColour2[p - 1]);
display.display();
}
} else {
display.clearDisplay();
display.setCursor(0, 16);
display.println("NO DATA RECIEVED");
display.display();
}
t++;
if (t > 7) {
t = 0;
}
if (k == 8) {
display.setCursor(0, 0);
display.println("TEST CONTINUITY PASS");
// Display buffer
display.display();
}
digitalWrite(portPins[i], LOW);
}
}
if (variableValue == 2) {
digitalWrite(portPins[1], LOW);
String binaryString3 = "00010000";
int p;
t = 4;
for (int i = 0; i < num2Pins; ++i) {
button.loop();
CLK_state = digitalRead(CLK_PIN);
if (CLK_state != prev_CLK_state && CLK_state == HIGH) {
if (digitalRead(DT_PIN) == HIGH) {
encoderPos = (encoderPos + 1) % 3;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
break;
} else {
encoderPos = (encoderPos - 1 + 3) % 3;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
break;
}
}
prev_CLK_state = CLK_state;
String center = binaryString3.substring(3, 5);
// Rotate the center characters
char temp = center[0];
center[0] = center[1];
center[1] = temp;
// Replace the rotated center back into the string
binaryString3.setCharAt(3, center[0]);
binaryString3.setCharAt(4, center[1]);
Serial.print("BIN: ");
Serial.println(binaryString3); // Print the binary representation
digitalWrite(bncPins[i], HIGH);
for (int w = 7; w >= 0; w--) {
int inverseIndex = binaryString3.length() - 1 - w;
digitalWrite(ledPins[w], binaryString3.charAt(inverseIndex) == '1' ? HIGH : LOW);
}
delay(300); // Adjust delay as needed
if (radio.available()) {
radio.read(&text, sizeof(text));
receivedMessage = text; // Copy char array to String object
Serial.print("RX: ");
Serial.println(receivedMessage);
delay(500);
if (binaryString3[t] == receivedMessage[t]) {
int p;
if (binaryString3 == "00010000") {
p = 1;
} else if (binaryString3 == "00001000") {
p = 2;
}
k++;
// Binary representation of matched pin
Serial.print("Pin ");
Serial.print(p);
Serial.println(" matched!");
display.clearDisplay();
display.setCursor(0, 16);
display.print("SENT: ");
display.println(binaryString3);
display.print("RECV: ");
display.println(receivedMessage);
display.setCursor(0, 40);
display.print("Pin:");
display.print(p);
display.print(" CONNECTED");
display.setCursor(0, 48);
display.print("WIRCLR: ");
display.print(wireColour3[p - 1]);
display.display();
} else {
if (binaryString3 == "00010000") {
p = 1;
} else if (binaryString3 == "00001000") {
p = 2;
}
display.clearDisplay();
display.setCursor(0, 0);
display.println("TEST CONTINUITY FAIL");
display.setCursor(0, 16);
display.print("SENT: ");
display.println(binaryString3);
display.print("RECV: ");
display.println(receivedMessage);
display.setCursor(0, 40);
display.print("Pin:");
display.print(p);
display.print("NOT CONNECTED");
display.setCursor(0, 48);
display.print("WIRCLR: ");
display.print(wireColour3[p - 1]);
display.display();
}
} else {
display.clearDisplay();
display.setCursor(0, 16);
display.println("NO DATA RECIEVED");
display.display();
}
t++;
if (t > 4) {
t = 3;
}
if (k == 2) {
display.setCursor(0, 0);
display.println("TEST CONTINUITY PASS");
display.display();
}
digitalWrite(bncPins[i], LOW);
}
}
if (variableValue == 3) {
digitalWrite(portPins[1], LOW);
String binaryString3 = "00010000";
t = 4;
for (int i = 0; i < num3Pins; ++i) {
button.loop();
CLK_state = digitalRead(CLK_PIN);
if (CLK_state != prev_CLK_state && CLK_state == HIGH) {
if (digitalRead(DT_PIN) == HIGH) {
encoderPos = (encoderPos + 1) % 3;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
break;
} else {
encoderPos = (encoderPos - 1 + 3) % 3;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
break;
}
}
prev_CLK_state = CLK_state;
String center = binaryString3.substring(3, 5);
// Rotate the center characters
char temp = center[0];
center[0] = center[1];
center[1] = temp;
// Replace the rotated center back into the string
binaryString3.setCharAt(3, center[0]);
binaryString3.setCharAt(4, center[1]);
Serial.print("BIN: ");
Serial.println(binaryString3); // Print the binary representation
digitalWrite(rj11Pins[i], HIGH);
for (int w = 7; w >= 0; w--) {
int inverseIndex = binaryString3.length() - 1 - w;
digitalWrite(ledPins[w], binaryString3.charAt(inverseIndex) == '1' ? HIGH : LOW);
}
delay(300);
if (radio.available()) {
radio.read(&text, sizeof(text));
receivedMessage = text; // Copy char array to String object
Serial.print("RX: ");
Serial.println(receivedMessage);
delay(500);
if (binaryString3[t] == receivedMessage[t]) {
int p;
if (binaryString3 == "00010000") {
p = 1;
} else if (binaryString3 == "00001000") {
p = 2;
}
k++;
// Binary representation of matched pin
Serial.print("Pin ");
Serial.print(p);
Serial.println(" matched!");
display.clearDisplay();
display.setCursor(0, 16);
display.print("SENT: ");
display.println(binaryString3);
display.print("RECV: ");
display.println(receivedMessage);
display.setCursor(0, 40);
display.print("Pin:");
display.print(p);
display.print(" CONNECTED");
display.display();
} else {
int p;
if (binaryString3 == "00010000") {
p = 1;
} else if (binaryString3 == "00001000") {
p = 2;
}
display.clearDisplay();
display.setCursor(0, 0);
display.println("TEST CONTINUITY FAIL");
display.setCursor(0, 16);
display.print("SENT: ");
display.println(binaryString3);
display.print("RECV: ");
display.println(receivedMessage);
display.setCursor(0, 40);
display.print("Pin:");
display.print(p);
display.print("NOT CONNECTED");
display.display();
}
} else {
display.clearDisplay();
display.setCursor(0, 16);
display.println("NO DATA RECIEVED");
display.display();
}
t++;
if (t > 4) {
t = 3;
}
if (k == 2) {
display.setCursor(0, 0);
display.println("TEST CONTINUITY PASS");
d++;
// Display buffer
display.display();
}
digitalWrite(rj11Pins[i], LOW);
}
}
}
}
void function2() {
String binaryString3 = "00010000";
String binaryValue = "00001000";
String binaryValue2 = "00000001";
int z = 0;
int p;
int sum = 0;
int k = 0;
char text[32] = "";
Serial.println("TEST SHORT SELECTED");
while (encoderPos == 1) {
display.clearDisplay();
if (variableValue == 0) {
for (int i = 0; i < numPins; i++) {
button.loop();
CLK_state = digitalRead(CLK_PIN);
if (CLK_state != prev_CLK_state && CLK_state == HIGH) {
if (digitalRead(DT_PIN) == HIGH) {
encoderPos = (encoderPos + 1) % 3;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
break;
} else {
encoderPos = (encoderPos - 1 + 3) % 3;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
break;
}
}
prev_CLK_state = CLK_state;
char lastBit = binaryValue[binaryValue.length() - 1]; // Store the last bit
binaryValue = lastBit + binaryValue.substring(0, binaryValue.length() - 1); // Shift all bits to the right
Serial.print("BIN: ");
char lastBit2 = binaryValue2[binaryValue2.length() - 1]; // Store the last bit
binaryValue2 = lastBit2 + binaryValue2.substring(0, binaryValue2.length() - 1); // Shift all bits to the right
Serial.println(binaryValue); // Print the binary representation
digitalWrite(portPins[i], HIGH);
for (int w = 0; w < 8; w++) {
digitalWrite(ledPins[w], binaryValue2.charAt(w) == '1' ? HIGH : LOW);
}
delay(300); // Adjust delay as needed
if (radio.available()) {
String receivedMessage = ""; // String object to store received message
char text[32] = "";
radio.read(&text, sizeof(text));
receivedMessage = text; // Copy char array to String object
for (int i = 0; i < receivedMessage.length(); i++) {
// Convert the character to an integer and add it to the sum
sum += receivedMessage[i] - '0'; // Subtract '0' to convert from ASCII to integer
}
Serial.println(sum);
Serial.print("RX: ");
Serial.println(receivedMessage);
delay(500);
if (binaryValue == receivedMessage) {
for (int i = 0; i < receivedMessage.length(); i++) {
// Convert the character to an integer and add it to the sum
sum += receivedMessage[i] - '0'; // Subtract '0' to convert from ASCII to integer
}
Serial.println(sum);
if (binaryValue == "10000000") {
p = 8;
} else if (binaryValue == "01000000") {
p = 7;
}
if (binaryValue == "00100000") {
p = 6;
} else if (binaryValue == "00010000") {
p = 5;
}
if (binaryValue == "00001000") {
p = 4;
} else if (binaryValue == "00000100") {
p = 3;
}
if (binaryValue == "00000010") {
p = 2;
} else if (binaryValue == "00000001") {
p = 1;
}
// Binary representation of matched pin
Serial.print("Pin ");
Serial.print(p);
Serial.println(" Clear");
display.clearDisplay();
display.setCursor(0, 16);
display.print("SENT: ");
display.println(binaryValue);
display.print("RECV: ");
display.println(receivedMessage);
display.setCursor(0, 40);
display.print("Pin:");
display.print(p);
display.print(" Clear");
display.setCursor(0, 48);
display.print("WIRCLR: ");
display.print(wireColour1[p - 1]);
display.display();
} else {
for (int i = 0; i < receivedMessage.length(); i++) {
// Convert the character to an integer and add it to the sum
sum += receivedMessage[i] - '0'; // Subtract '0' to convert from ASCII to integer
}
Serial.println(sum);
if (binaryValue == "10000000") {
p = 8;
} else if (binaryValue == "01000000") {
p = 7;
}
if (binaryValue == "00100000") {
p = 6;
} else if (binaryValue == "00010000") {
p = 5;
}
if (binaryValue == "00001000") {
p = 4;
} else if (binaryValue == "00000100") {
p = 3;
}
if (binaryValue == "00000010") {
p = 2;
} else if (binaryValue == "00000001") {
p = 1;
}
// Binary representation of matched pin
Serial.print("Pin ");
Serial.print(p);
Serial.println(" Clear");
display.clearDisplay();
display.setCursor(0, 16);
display.print("SENT: ");
display.println(binaryValue);
display.print("RECV: ");
display.println(receivedMessage);
display.setCursor(0, 40);
display.print("Pin:");
display.print(p);
display.print(" SHORT");
display.setCursor(0, 48);
display.print("WIRCLR: ");
display.print(wireColour1[p - 1]);
display.display();
}
if (sum == 1) {
z++;
sum = 0;
} else if (sum >= 1) {
k++;
}
} else {
display.clearDisplay();
display.setCursor(0, 16);
display.println("NO DATA RECIEVED");
display.display();
}
if (z >= 8) {
display.setCursor(0, 0);
display.println("TEST SHORT: PASS");
display.display();
z = 1;
} else if (k > 1) {
Serial.println(k);
display.setCursor(0, 0);
display.println("TEST SHORT: FAIL");
display.display();
k = 0;
}
digitalWrite(portPins[i], LOW);
}
}
if (variableValue == 1) {
for (int i = 0; i < numPins; i++) {
button.loop();
CLK_state = digitalRead(CLK_PIN);
if (CLK_state != prev_CLK_state && CLK_state == HIGH) {
if (digitalRead(DT_PIN) == HIGH) {
encoderPos = (encoderPos + 1) % 3;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
break;
} else {
encoderPos = (encoderPos - 1 + 3) % 3;
Serial.print("encoderPos: ");
Serial.println(encoderPos);
break;
}
}
prev_CLK_state = CLK_state;
char lastBit = binaryValue[binaryValue.length() - 1]; // Store the last bit
binaryValue = lastBit + binaryValue.substring(0, binaryValue.length() - 1); // Shift all bits to the right
Serial.print("BIN: ");
char lastBit2 = binaryValue2[binaryValue2.length() - 1]; // Store the last bit
binaryValue2 = lastBit2 + binaryValue2.substring(0, binaryValue2.length() - 1); // Shift all bits to the right
Serial.println(binaryValue); // Print the binary representation
digitalWrite(portPins[i], HIGH);
for (int w = 0; w < 8; w++) {
digitalWrite(ledPins[w], binaryValue2.charAt(w) == '1' ? HIGH : LOW);
}
delay(300); // Adjust delay as needed
if (radio.available()) {
String receivedMessage = ""; // String object to store received message
char text[32] = "";
radio.read(&text, sizeof(text));
receivedMessage = text; // Copy char array to String object
for (int i = 0; i < receivedMessage.length(); i++) {
// Convert the character to an integer and add it to the sum
sum += receivedMessage[i] - '0'; // Subtract '0' to convert from ASCII to integer
}
Serial.println(sum);
Serial.print("RX: ");
Serial.println(receivedMessage);
delay(500);
if (binaryValue == receivedMessage) {
for (int i = 0; i < receivedMessage.length(); i++) {
// Convert the character to an integer and add it to the sum
sum += receivedMessage[i] - '0'; // Subtract '0' to convert from ASCII to integer
}
Serial.println(sum);
if (binaryValue == "10000000") {
p = 8;
} else if (binaryValue == "01000000") {
p = 7;
}
if (binaryValue == "00100000") {
p = 6;
} else if (binaryValue == "00010000") {
p = 5;
}
if (binaryValue == "00001000") {
p = 4;
} else if (binaryValue == "00000100") {
p = 3;
}
if (binaryValue == "00000010") {
p = 2;
} else if (binaryValue == "00000001") {