#include <LiquidCrystal_I2C.h> // Include the LiquidCrystal_I2C library if not already done
const int startButtonPin = 9; // New pin number for the start button
const int endButtonPin = 8; // New pin number for the end button
const int numPins = 6; // Number of pins being tested
const int outputPins[numPins] = {7, 6, 5, 4, 3, 2}; // Output pin numbers (7-2)
const int inputPins[numPins] = {14, 15, 16, 17, 18, 19}; // Input pin numbers (14-19)
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C LCD display, replace the address (0x27) if different
bool testRunning = false;
void displayMessage(const char* message, int col, int row) {
lcd.setCursor(col, row);
lcd.print(message);
}
void startTest() {
testRunning = true;
lcd.clear();
displayMessage("Test Running...", 0, 0);
delay(2000); // Display "Test Running..." message for 2 seconds
lcd.clear();
displayMessage("Double Checking", 0, 0);
displayMessage("Please Wait...", 0, 1);
delay(2000); // Display "Double Checking" message for 2 seconds
lcd.clear();
displayMessage("Test Ready!", 0, 0);
displayMessage("Press End Button", 0, 1);
}
void endTest() {
testRunning = false;
lcd.clear();
lcd.print("Results: ");
int numConnected = 0; // Counter for the number of successful connections
int failedPins[numPins];
int numFailedPins = 0;
// Perform the test and check the connections
for (int i = 0; i < numPins; i++) {
pinMode(outputPins[i], OUTPUT);
digitalWrite(outputPins[i], HIGH);
delay(50); // Allow time for the output to stabilize
pinMode(inputPins[i], INPUT);
bool connected = digitalRead(inputPins[i]) == HIGH;
lcd.setCursor(i, 1);
lcd.print(connected ? "O" : "X");
digitalWrite(outputPins[i], LOW); // Reset output pin
if (connected) {
numConnected++; // Increment the counter for successful connections
} else {
failedPins[numFailedPins++] = i; // Record the failed pin number
}
}
delay(2000); // Display results for 2 seconds
lcd.clear();
if (numConnected == numPins) {
lcd.print("PASS");
delay(2000); // Display "PASS" for 2 seconds
lcd.clear();
lcd.print("Result: ");
lcd.print(numConnected);
lcd.print("/");
lcd.print(numPins);
delay(2000); // Display "FAIL" for 2 seconds
lcd.clear();
lcd.print("No Error"); // Display "No Error" for "PASS"
} else {
lcd.print("FAIL");
delay(2000); // Display "FAIL" for 2 seconds
lcd.clear();
lcd.print("Error Pins:");
for (int i = 0; i < numFailedPins; i++) {
int failedOutputPin = outputPins[failedPins[i]];
int failedInputPin = inputPins[failedPins[i]];
lcd.clear();
lcd.print("Result: ");
lcd.print(numConnected);
lcd.print("/");
lcd.print(numPins);
delay(2000); // Display "FAIL" for 2 seconds
lcd.clear();
// Display failed output pin in the first column
lcd.setCursor(0, 0);
lcd.print("Missing Link ");
// Display failed input pin in the second column
lcd.setCursor(0, 1); // Adjust the column number as needed based on your LCD dimensions
lcd.print("Pin ");
lcd.print(failedOutputPin);
lcd.print(" to Pin ");
lcd.print(failedInputPin);
delay(2000); // Display each failed pin for 2 seconds
}
}
}
void setup() {
pinMode(startButtonPin, INPUT_PULLUP);
pinMode(endButtonPin, INPUT_PULLUP);
lcd.begin(16, 2);
displayMessage("Press Start", 0, 0);
displayMessage("To Begin", 1, 1);
}
void loop() {
if (!testRunning && digitalRead(startButtonPin) == LOW) {
startTest();
}
if (testRunning && digitalRead(endButtonPin) == LOW) {
endTest();
// Wait for the end button to be released before allowing a new test
while (digitalRead(endButtonPin) == LOW) {
// Continue checking end button state until it's released
}
}
}