So I have code that tests a cable harness. Here it is below:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
//Arrays to set which pins are outputs and which are inputs:
int outPin[] = {2, 3, 4, 5, 6, 7, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35};
int inPin[] = {8, 9, 10, 11, 12, 50, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 53};
int pin_size = 20;
int loop_count = 0;
int voltage;
void setup() {
lcd.init();
lcd.backlight();
//initialize the digital pin as an output or input:
pinMode((int)outPin, OUTPUT);
pinMode((int)inPin, INPUT);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0,0);
lcd.print("Welcome to my");
lcd.setCursor(0,1);
lcd.print("Cable Tester!");
delay(3000);
lcd.clear();
}
void loop() {
// Send the outputs.
digitalWrite(outPin[loop_count], HIGH);
delay(100);
digitalWrite(outPin[loop_count], LOW);
delay(100);
// Receive the inputs:
voltage = digitalRead(inPin[loop_count]);
lcd.print ("Cable " + String(inPin[loop_count]) + ": ");
// LCD prints PASS or FAIL status using a switch statement:
switch (voltage){
case HIGH:
lcd.print("PASS");
break;
case LOW:
lcd.print("FAIL");
break;
default:
lcd.print("UNKNOWN");
}
// Delay and increment the loop counter for the next set of pins.
delay(1000);
loop_count++;
lcd.clear();
// Check if reached the end of all pins.
if (loop_count == pin_size){
lcd.print ("Reached end!");
delay(1000);
lcd.clear();
lcd.print("Testing again...");
delay(1000);
lcd.clear();
loop_count = 0;
}
}
My circuit is simple. I'm using an Arduino mega board, with the cables connected directly to the digital I/O pins and LCD using an I2C bus.
I'm close to being finished but I am struggling to include code that'll check for crossed wires. I know to assign 2 pins per cable like:
int j = 20;
int CABLE_A[] = {2, 8};
int CABLE_B[] = {3, 9};
But I'm unsure if there is anything else I must add. Any pointers?
Thank you.